﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using BUS;
using LinQ_DTO;
using System.Collections.Generic;

namespace EFashion.Employee
{
    public partial class controller : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

       //******************************************************************************************
       // * LOAI SAN PHAM 
       // *****************************************************************************************

        public void manage_kinds_of_product()
        {
            String page = "";
            if (Request.QueryString["page"] == null)
            {
                return;
            }
            else
            {
                page = Request.QueryString["page"];
                if (page.Substring(0, 1).ToString().CompareTo("\"") == 0)
                {
                    page = page.Substring(1, page.Length - 2);
                }
            }

            String strPage = '"'+page+'"';
            LoaiSanPhamBUS loai_san_pham_BUS = new LoaiSanPhamBUS();
            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            int iStart = (int.Parse(page) - 1)*iLimit;
            List<shop_loaisanpham> loai_san_pham_list = loai_san_pham_BUS.layLoaiSanPhamGioiHan(iStart,iLimit);
            int totalrow = loai_san_pham_BUS.laySoLuongLoaiSanPham();
            String strTotalrow = '"' + totalrow.ToString() + '"';
            String strCount = '"'+"-1"+'"';
            String strContext = "";

            Response.Write("<div id='content_management'>");
            Response.Write("<h1 id='management_title'>Quản lý loại sản phẩm</h1>");
            Response.Write("<br/>");
            Response.Write("<table border='0'><tbody><tr><td>");
            Response.Write("<input type='text' id='key_search' size='50' maxlength='100'/></td><td>");
            Response.Write("<div class='art-button-wrapper' valign='bottom'>");
            Response.Write("<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_search_kinds_of_product(\"default\",\"-1\",\"10\",\"-1\");return false;'><span>Tìm kiếm</span></a>");
            Response.Write("</div>");
            Response.Write("</td></tr></tbody></table>");/*end: table tim_kiem */
            Response.Write("<div id='management_list'>");

            Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
            Response.Write("<tbody>");
            Response.Write("<tr class='management_table_header' style='text-align: center;'>");
            Response.Write("<td width='5%' align='center'><input type='checkBox' id='checkAllTop' onclick='process_check_management(this.id)'></td>");
            Response.Write("<td width='65%'>Tên</td>");
            Response.Write("<td width='15%'></td>");
            Response.Write("<td width='15%'></td>");
            Response.Write("</tr>");

            int j = 1;
            String strSearch = '"' + "false" + '"';
            for (int i = 0; i < loai_san_pham_list.Count(); i++)
            {
                if (j == 1)
                {
                    Response.Write("<tr class='management_celllight1'>");
                    j = 0;
                }
                else
                {
                    Response.Write("<tr class='management_celllight0'>");
                    j = 1;
                }
                Response.Write("<td align='center'><input type='checkbox' id='checkedIDList[]' name='checkedIDList[]' value='" + loai_san_pham_list[i].MaLoaiSanPham + "'/></td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + loai_san_pham_list[i].TenLoaiSanPham + "</td>");
                String strId = '"' + loai_san_pham_list[i].MaLoaiSanPham.ToString() + '"';
                Response.Write("<td align='center' style='padding: 5px;'>" + 
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' title='Xóa' onclick='ajax_delete_kinds_of_product("+strId+","+strTotalrow+","+strLimit+","+strSearch+");return false;'><span>Xóa</span></a>" +
                    "</div>" + "</td>");
                Response.Write("<td align='center' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' title='Xóa' onclick='ajax_update_kinds_of_product_getform("+strId+");return false;'><span>Cập nhật</span></a>"
                    + "</div>" + "</td>");
                Response.Write("</tr>");
            }
            if (loai_san_pham_list.Count() > 0)
            {
                Response.Write("<tr>" + "<td align='center'><input type='checkBox' id='checkAllBottom' onclick='process_check_management(this.id)'></td>");
                Response.Write("<td align='left' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' title='Xóa' onclick='ajax_delete_checked_kinds_of_product(" + strTotalrow + "," + strLimit + "," + strSearch + ");return false;'><span>Xóa chọn</span></a>"
                    + "</div>" + "</td>");
                Response.Write("<td></td>");
                Response.Write("<td align='left' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' title='Thêm' onclick='ajax_add_new_kinds_of_product_getform();return false;'><span>Thêm</span></a>"
                    + "</div>" + "</td>");
                Response.Write("</tr>");
            }
            Response.Write("</tbody>");
            Response.Write("</table>");
            Response.Write("</div>"); /*end: div management_list */
            Response.Write("<div align='center'>");
            strContext = '"'+"previous"+'"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_kinds_of_product("+strContext+","+strTotalrow+","+strLimit+","+strCount+");return false;'><span>Lùi</span></a>" +
                "</div>");
            float fLimit = 10;
            double totalPage = Math.Ceiling(totalrow / fLimit);
            Response.Write("<font id='pageIndex' size='6'>"+page+"/"+totalPage+"</font>");
            strContext = '"' + "next" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_kinds_of_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Tiếp</span></a>" +
                "</div>");
            Response.Write("</div>"); /*end: div pageIndex */
            Response.Write("<div><select id=''>");
            strContext = '"' + "jump" + '"';
            for (int i = 1; i <= totalPage; i++)
            {
                if (i == int.Parse(page))
                {
                    Response.Write("<option id='' selected value='" + i + "'>"+i+"</option>");
                }
                else
                {
                    strCount = '"' + i.ToString() + '"';
                    Response.Write("<option id='' value='" + i + "' onclick='ajax_manage_kinds_of_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                }
            }
            Response.Write("</select></div>");/*end: select */
            Response.Write("</div>"); /*end: div content_management */
        }

        public void delete_kinds_of_product()
        {
            String id = "";
            if (Request.QueryString["id"] != null)
            {
                id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }
            }
            else
            {
                return;
            }

            int iID = int.Parse(id);
            LoaiSanPhamBUS loai_san_pham_BUS = new LoaiSanPhamBUS();
            loai_san_pham_BUS.XoaLoaiSanPhamTheoMa(iID);
        }

        public void delete_checked_kinds_of_product()
        {
            String checkedIDList = "";
            if (Request.QueryString["checkedIDList"] != null)
            {
                checkedIDList = Request.QueryString["checkedIDList"];
                if (checkedIDList.Substring(0, 1).ToString().CompareTo("\"") == 0)
                {
                    checkedIDList = checkedIDList.Substring(1, checkedIDList.Length - 2);
                }
            }
            else
            {
                return;
            }
            String[] arrCheckedID = checkedIDList.Split(',');
            int count = arrCheckedID.Count();
            int iID = -1;
            LoaiSanPhamBUS loai_san_pham_BUS = new LoaiSanPhamBUS();
            for (int i = 0; i < count; i++)
            {
                iID = int.Parse(arrCheckedID[i]);
                loai_san_pham_BUS.XoaLoaiSanPhamTheoMa(iID);
            }
        }

        public void update_kinds_of_product()
        {
            if (Request.QueryString["get_form"] != null)
            {
                String id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }

                String key_search = "";
                if (Request.QueryString["key_search"] != null)
                {
                    key_search = Request.QueryString["key_search"];
                    if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0)
                    {
                        key_search = key_search.Substring(1, key_search.Length - 2);
                    }
                }

                String strID = '"' +id+ '"';
                String strContext = '"' + "default" + '"';
                String strTotalrow = '"' + "-1" + '"';
                String strLimit = '"' + "10" + '"';
                String strCount = '"' + "-1" + '"';
                if (key_search.CompareTo("") == 0)
                {
                    Response.Write("<h4><a href='#' onclick='ajax_manage_kinds_of_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
                }
                else
                {
                    String strKeySearch = '"' + key_search + '"';
                    Response.Write("<h4><a href='#' onclick='ajax_search_kinds_of_product(" + strKeySearch + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
                }
                Response.Write("<br/>");

                LoaiSanPhamBUS loai_san_pham_BUS = new LoaiSanPhamBUS();
                //List<shop_loaisanpham> loai_san_pham = loai_san_pham_BUS.LayLoaiSanPhamTheoMa(int.Parse(id));
                shop_loaisanpham loai_san_pham = loai_san_pham_BUS.LayLoaiSanPhamTheoMa(int.Parse(id));
                Response.Write("<div class='cmxform' id='update_kinds_of_product_form'>");
                Response.Write("<fieldset>");
                Response.Write("<legend>Thông tin loại sản phẩm</legend>");
                Response.Write("<p>");
                Response.Write("<input type='hidden' id='kinds_of_product_id' value='"+strID+"'/>");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='name'>Tên</label>");
                Response.Write("<input id='name' value='"+loai_san_pham.TenLoaiSanPham.ToString()+"' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_update_kinds_of_product_process();return false;'><span>Cập nhật</span></a>" +
                    "</div>");
                Response.Write("</fieldset>");
                Response.Write("</div>"); /*end: div update_kinds_of_product_form */
            }
            else /* if (Request.QueryString["send_info"] != null) */
            {
                String id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }

                String name = Request.QueryString["name"];
                shop_loaisanpham lspLinq = new shop_loaisanpham();
                lspLinq.MaLoaiSanPham = int.Parse(id);
                lspLinq.TenLoaiSanPham = name;
                LoaiSanPhamBUS loai_san_pham_BUS = new LoaiSanPhamBUS();
                loai_san_pham_BUS.CapNhatSP(lspLinq);
            }
        }

        public void search_kinds_of_product()
        {
            String key_search = "";
            if (Request.QueryString["key_search"] == null)
            {
                return;
            }
            else
            {
                key_search = Request.QueryString["key_search"];
                if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0)
                {
                    key_search = key_search.Substring(1, key_search.Length - 2);
                }
            }

            LoaiSanPhamBUS lspBUS = new LoaiSanPhamBUS();
            List<shop_loaisanpham> lspList = lspBUS.LayLoaiSanPhamTheoKhoa(key_search);
            int totalrow = lspList.Count();
            String strKeySearch = '"' + key_search + '"';
            String strContext = '"' + "default" + '"';
            String strTotalrow = '"' + totalrow.ToString() + '"';
            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            Response.Write("<h4><a href='#' onclick='ajax_manage_kinds_of_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            Response.Write("<br/>");

            if (lspList.Count() == 0)
            {
                Response.Write("<h4>Không có dữ liệu loại sản phẩm nào thích hợp với từ khóa \""+key_search+"\"</h4>");
            }
            else
            {
                String page = "";
                if (Request.QueryString["page"] == null)
                {
                    return;
                }
                else
                {
                    page = Request.QueryString["page"];
                    if (page.Substring(0, 1).ToString().CompareTo("\"") == 0)
                    {
                        page = page.Substring(1, page.Length - 2);
                    }
                }

                String strPage = '"' + page + '"';
                int iStart = iLimit * (int.Parse(page)-1);
                int iEnd = iLimit * int.Parse(page);
                if (iEnd > totalrow)
                {
                    iEnd = totalrow;
                }

                Response.Write("<div id='content_management'>");
                Response.Write("<h4 id='management_title'>Kết quả tìm kiếm loại sản phẩm với từ khóa \"" + key_search + "\"</h4>");
                Response.Write("<table border='0'><tbody><tr><td>");
                Response.Write("<input type='text' id='key_search' value='"+key_search+"' size='50' maxlength='100'/></td><td>");
                Response.Write("<div class='art-button-wrapper' valign='bottom'>");
                Response.Write("<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_kinds_of_product(\"default\",\"-1\",\"10\",\"-1\");return false;'><span>Tìm kiếm</span></a>");
                Response.Write("</div>");
                Response.Write("</td></tr></tbody></table>");/*end: table tim_kiem */
                Response.Write("<div id='management_list'>");

                Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
                Response.Write("<tbody>");
                Response.Write("<tr class='management_table_header' style='text-align: center;'>");
                Response.Write("<td width='5%' align='center'><input type='checkBox' id='checkAllTop' onclick='process_check_management(this.id)'></td>");
                Response.Write("<td width='65%'>Tên</td>");
                Response.Write("<td width='15%'></td>");
                Response.Write("<td width='15%'></td>");
                Response.Write("</tr>");

                int j = 1;
                String strSearch = '"' + "true" + '"';

                for (int i = iStart; i < iEnd; i++)
                {
                    if (j == 1)
                    {
                        Response.Write("<tr class='management_celllight1'>");
                        j = 0;
                    }
                    else
                    {
                        Response.Write("<tr class='management_celllight0'>");
                        j = 1;
                    }
                    Response.Write("<td align='center'><input type='checkbox' id='checkedIDList[]' name='checkedIDList[]' value='" + lspList[i].MaLoaiSanPham + "'/></td>");
                    Response.Write("<td align='left' style='padding: 5px;'>" + lspList[i].TenLoaiSanPham + "</td>");
                    String strId = '"' + lspList[i].MaLoaiSanPham.ToString() + '"';
                    Response.Write("<td align='center' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_delete_kinds_of_product(" + strId + "," + strTotalrow + "," + strLimit + ","+strSearch+");return false;'><span>Xóa</span></a>" +
                        "</div>" + "</td>");
                    Response.Write("<td align='center' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_update_kinds_of_product_getform(" + strId + ");return false;'><span>Cập nhật</span></a>"
                        + "</div>" + "</td>");
                    Response.Write("</tr>");
                }
                if (lspList.Count() > 0)
                {
                    Response.Write("<tr>" + "<td align='center'><input type='checkBox' id='checkAllBottom' onclick='process_check_management(this.id)'></td>");
                    Response.Write("<td align='left' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_delete_checked_kinds_of_product(" + strTotalrow + "," + strLimit + "," + strSearch + ");return false;'><span>Xóa chọn</span></a>"
                        + "</div>" + "</td>");
                    Response.Write("</tr>");
                }
                Response.Write("</tbody>");
                Response.Write("</table>");
                Response.Write("</div>"); /*end: div management_list */
                Response.Write("<div align='center'>");
                strContext = '"' + "previous" + '"';
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_kinds_of_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Lùi</span></a>" +
                    "</div>");
                float fLimit = 10;
                double totalPage = Math.Ceiling(totalrow / fLimit);
                Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
                strContext = '"' + "next" + '"';
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_kinds_of_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Tiếp</span></a>" +
                    "</div>");

                Response.Write("<div><select id=''>");
                strContext = '"' + "jump" + '"';
                for (int i = 1; i <= totalPage; i++)
                {
                    if (i == int.Parse(page))
                    {
                        Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                    }
                    else
                    {
                        strCount = '"' + i.ToString() + '"';
                        Response.Write("<option id='' value='" + i + "' onclick='ajax_search_kinds_of_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                    }
                }
                Response.Write("</select></div>");/*end: select */
            }

        }

        public void add_new_kinds_of_product()
        {
            if (Request.QueryString["get_form"] != null)
            {
                String strContext = '"' + "default" + '"';
                String strTotalrow = '"' + "-1" + '"';
                String strLimit = '"' + "10" + '"';
                String strCount = '"' + "-1" + '"';
                Response.Write("<h4><a href='#' onclick='ajax_manage_kinds_of_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
                Response.Write("<br/>");
                
                Response.Write("<div class='cmxform' id='update_kinds_of_product_form'>");
                Response.Write("<fieldset>");
                Response.Write("<legend>Thông tin loại sản phẩm</legend>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='name'>Tên</label>");
                Response.Write("<input id='name' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_add_new_kinds_of_product_process();return false;'><span>Thêm</span></a>" +
                    "</div>");
                Response.Write("</fieldset>");
                Response.Write("</div>"); /*end: div update_kinds_of_product_form */
            }
            else /* if (Request.QueryString["send_info"] != null) */
            {
                String name = "";
                if (Request.QueryString["name"] != null)
                {
                    name = Request.QueryString["name"];
                    if (name.Substring(0, 1).ToString().CompareTo("\"") == 0 || 
                        name.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        name = name.Substring(1, name.Length - 2);
                    }
                }
                else
                {
                    return;
                }
                shop_loaisanpham lspLinq = new shop_loaisanpham();
                lspLinq.TenLoaiSanPham = name;
                LoaiSanPhamBUS lsp_BUS = new LoaiSanPhamBUS();
                lsp_BUS.ThemLoaiSanPham(lspLinq);
            }
        }

        //**************************************************************************************************
        // * NHA SAN XUAT
        // *************************************************************************************************

        public void manage_manufacturer()
        {
            String page = "";
            if (Request.QueryString["page"] == null)
            {
                return;
            }
            else
            {
                page = Request.QueryString["page"];
                if (page.Substring(0, 1).ToString().CompareTo("\"") == 0)
                {
                    page = page.Substring(1, page.Length - 2);
                }
            }

            String strPage = '"' + page + '"';
            NhaSanXuatBUS nsx_BUS = new NhaSanXuatBUS();
            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            int iStart = (int.Parse(page) - 1) * iLimit;
            List<shop_nhasanxuat> nsx_list = nsx_BUS.layNhaSanXuatGioiHan(iStart, iLimit);
            int totalrow = nsx_BUS.laySoLuongNhaSanXuat();
            String strTotalrow = '"' + totalrow.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            String strContext = "";

            Response.Write("<div id='content_management'>");
            Response.Write("<h1 id='management_title'>Quản lý nhà sản xuất</h1>");
            Response.Write("<br/>");
            Response.Write("<table border='0'><tbody><tr><td>");
            Response.Write("<input type='text' id='key_search' size='50' maxlength='100'/></td><td>");
            Response.Write("<div class='art-button-wrapper' valign='bottom'>");
            Response.Write("<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_search_manufacturer(\"default\",\"-1\",\"10\",\"-1\");return false;'><span>Tìm kiếm</span></a>");
            Response.Write("</div>");
            Response.Write("</td></tr></tbody></table>");/*end: table tim_kiem */
            Response.Write("<div id='management_list'>");

            Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
            Response.Write("<tbody>");
            Response.Write("<tr class='management_table_header' style='text-align: center;'>");
            Response.Write("<td width='5%' align='center'><input type='checkBox' id='checkAllTop' onclick='process_check_management(this.id)'></td>");
            Response.Write("<td width='25%'>Tên</td>");
            Response.Write("<td width='40%'>Thông tin nhà sản xuất</td>");
            Response.Write("<td width='15%'></td>");
            Response.Write("<td width='15%'></td>");
            Response.Write("</tr>");

            int j = 1;
            String strSearch = '"' + "false" + '"';
            for (int i = 0; i < nsx_list.Count(); i++)
            {
                if (j == 1)
                {
                    Response.Write("<tr class='management_celllight1'>");
                    j = 0;
                }
                else
                {
                    Response.Write("<tr class='management_celllight0'>");
                    j = 1;
                }
                Response.Write("<td align='center'><input type='checkbox' id='checkedIDList[]' name='checkedIDList[]' value='" + nsx_list[i].MaNhaSanXuat + "'/></td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + nsx_list[i].TenNhaSanXuat + "</td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + nsx_list[i].ThongTinNhaSanXuat + "</td>");
                String strId = '"' + nsx_list[i].MaNhaSanXuat.ToString() + '"';
                Response.Write("<td align='center' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' title='Xóa' onclick='ajax_delete_manufacturer(" + strId + "," + strTotalrow + "," + strLimit + "," + strSearch + ");return false;'><span>Xóa</span></a>" +
                    "</div>" + "</td>");
                Response.Write("<td align='center' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' title='Xóa' onclick='ajax_update_manufacturer_getform(" + strId + ");return false;'><span>Cập nhật</span></a>"
                    + "</div>" + "</td>");
                Response.Write("</tr>");
            }
            if (nsx_list.Count() > 0)
            {
                Response.Write("<tr>" + "<td align='center'><input type='checkBox' id='checkAllBottom' onclick='process_check_management(this.id)'></td>");
                Response.Write("<td align='left' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' title='Xóa' onclick='ajax_delete_checked_manufacturer(" + strTotalrow + "," + strLimit + "," + strSearch + ");return false;'><span>Xóa chọn</span></a>"
                    + "</div>" + "</td>");
                Response.Write("<td></td>");
                Response.Write("<td></td>");
                Response.Write("<td align='left' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' title='Thêm' onclick='ajax_add_new_manufacturer_getform();return false;'><span>Thêm</span></a>"
                    + "</div>" + "</td>");
                Response.Write("</tr>");
            }
            Response.Write("</tbody>");
            Response.Write("</table>");
            Response.Write("</div>"); /*end: div management_list */
            Response.Write("<div align='center'>");
            strContext = '"' + "previous" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_manufacturer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Lùi</span></a>" +
                "</div>");
            float fLimit = 10;
            double totalPage = Math.Ceiling(totalrow / fLimit);
            Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
            strContext = '"' + "next" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_manufacturer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Tiếp</span></a>" +
                "</div>");
            Response.Write("</div>"); /*end: div pageIndex */
            Response.Write("<div><select id=''>");
            strContext = '"' + "jump" + '"';
            for (int i = 1; i <= totalPage; i++)
            {
                if (i == int.Parse(page))
                {
                    Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                }
                else
                {
                    strCount = '"' + i.ToString() + '"';
                    Response.Write("<option id='' value='" + i + "' onclick='ajax_manage_manufacturer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                }
            }
            Response.Write("</select></div>");/*end: select */
            Response.Write("</div>"); /*end: div content_management */
        }

        public void delete_manufacturer()
        {
            String id = "";
            if (Request.QueryString["id"] != null)
            {
                id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }
            }
            else
            {
                return;
            }

            int iID = int.Parse(id);
            NhaSanXuatBUS nsx_BUS = new NhaSanXuatBUS();
            nsx_BUS.XoaNhaSanXuat(iID);
        }

        public void delete_checked_manufacturer()
        {
            String checkedIDList = "";
            if (Request.QueryString["checkedIDList"] != null)
            {
                checkedIDList = Request.QueryString["checkedIDList"];
                if (checkedIDList.Substring(0, 1).ToString().CompareTo("\"") == 0)
                {
                    checkedIDList = checkedIDList.Substring(1, checkedIDList.Length - 2);
                }
            }
            else
            {
                return;
            }
            String[] arrCheckedID = checkedIDList.Split(',');
            int count = arrCheckedID.Count();
            int iID = -1;
            NhaSanXuatBUS nsx_BUS = new NhaSanXuatBUS();
            for (int i = 0; i < count; i++)
            {
                iID = int.Parse(arrCheckedID[i]);
                nsx_BUS.XoaNhaSanXuat(iID);
            }
        }

        public void update_manufacturer()
        {
            if (Request.QueryString["get_form"] != null)
            {
                String id = "";
                if (Request.QueryString["id"] != null)
                {
                    id = Request.QueryString["id"];
                    if (id.Substring(0, 1).ToString().CompareTo("\"") == 0)
                    {
                        id = id.Substring(1, id.Length - 2);
                    }
                }

                String key_search = "";
                if (Request.QueryString["key_search"] != null)
                {
                    key_search = Request.QueryString["key_search"];
                    if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0)
                    {
                        key_search = key_search.Substring(1, key_search.Length - 2);
                    }
                }

                String strID = '"' + id + '"';
                String strContext = '"' + "default" + '"';
                String strTotalrow = '"' + "-1" + '"';
                String strLimit = '"' + "10" + '"';
                String strCount = '"' + "-1" + '"';
                if (key_search.CompareTo("") == 0)
                {
                    Response.Write("<h4><a href='#' onclick='ajax_manage_manufacturer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
                }
                else
                {
                    String strKeySearch = '"' + key_search + '"';
                    Response.Write("<h4><a href='#' onclick='ajax_search_manufacturer(" + strKeySearch + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
                }
                Response.Write("<br/>");

                NhaSanXuatBUS nsx_BUS = new NhaSanXuatBUS();
                //List<shop_loaisanpham> loai_san_pham = loai_san_pham_BUS.LayLoaiSanPhamTheoMa(int.Parse(id));
                shop_nhasanxuat nsx = nsx_BUS.LayNhaSanXuatsTheoMa(int.Parse(id));
                Response.Write("<div class='cmxform' id='update_manufacturer_form'>");
                Response.Write("<fieldset>");
                Response.Write("<legend>Thông tin nhà sản xuất</legend>");
                Response.Write("<p>");
                Response.Write("<input type='hidden' id='manufacturer_id' value='" + strID + "'/>");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='name'>Tên</label>");
                Response.Write("<input id='name' value='" + nsx.TenNhaSanXuat.ToString() + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='name'>Thông tin</label>");
                Response.Write("<input id='info' value='" + nsx.ThongTinNhaSanXuat.ToString() + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_update_manufacturer_process();return false;'><span>Cập nhật</span></a>" +
                    "</div>");
                Response.Write("</fieldset>");
                Response.Write("</div>"); /*end: div update_manufacturer */
            }
            else /* if (Request.QueryString["send_info"] != null) */
            {
                String id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }

                String name = Request.QueryString["name"];
                String info = Request.QueryString["info"];
                shop_nhasanxuat lspLinq = new shop_nhasanxuat();
                lspLinq.MaNhaSanXuat = int.Parse(id);
                lspLinq.TenNhaSanXuat = name;
                lspLinq.ThongTinNhaSanXuat = info;
                NhaSanXuatBUS nsx_BUS = new NhaSanXuatBUS();
                nsx_BUS.CapNhatNhaSanXuat(lspLinq);
            }
        }

        public void search_manufacturer()
        {
            String key_search = "";
            if (Request.QueryString["key_search"] == null)
            {
                return;
            }
            else
            {
                key_search = Request.QueryString["key_search"];
                if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0)
                {
                    key_search = key_search.Substring(1, key_search.Length - 2);
                }
            }

            NhaSanXuatBUS nsx_BUS = new NhaSanXuatBUS();
            List<shop_nhasanxuat> nsx_list = nsx_BUS.LayNhaSanXuatTheoKhoa(key_search);
            int totalrow = nsx_list.Count();
            String strKeySearch = '"' + key_search + '"';
            String strContext = '"' + "default" + '"';
            String strTotalrow = '"' + totalrow.ToString() + '"';
            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            Response.Write("<h4><a href='#' onclick='ajax_manage_manufacturer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            Response.Write("<br/>");

            if (nsx_list.Count() == 0)
            {
                Response.Write("<h4>Không có dữ liệu nhà sản xuất nào thích hợp với từ khóa \"" + key_search + "\"</h4>");
            }
            else
            {
                String page = "";
                if (Request.QueryString["page"] == null)
                {
                    return;
                }
                else
                {
                    page = Request.QueryString["page"];
                    if (page.Substring(0, 1).ToString().CompareTo("\"") == 0)
                    {
                        page = page.Substring(1, page.Length - 2);
                    }
                }

                String strPage = '"' + page + '"';
                int iStart = iLimit * (int.Parse(page) - 1);
                int iEnd = iLimit * int.Parse(page);
                if (iEnd > totalrow)
                {
                    iEnd = totalrow;
                }

                Response.Write("<div id='content_management'>");
                Response.Write("<h4 id='management_title'>Kết quả tìm kiếm nhà sản xuất với từ khóa \"" + key_search + "\"</h4>");
                Response.Write("<table border='0'><tbody><tr><td>");
                Response.Write("<input type='text' id='key_search' value='" + key_search + "' size='50' maxlength='100'/></td><td>");
                Response.Write("<div class='art-button-wrapper' valign='bottom'>");
                Response.Write("<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_manufacturer(\"default\",\"-1\",\"10\",\"-1\");return false;'><span>Tìm kiếm</span></a>");
                Response.Write("</div>");
                Response.Write("</td></tr></tbody></table>");/*end: table tim_kiem */
                Response.Write("<div id='management_list'>");

                Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
                Response.Write("<tbody>");
                Response.Write("<tr class='management_table_header' style='text-align: center;'>");
                Response.Write("<td width='5%' align='center'><input type='checkBox' id='checkAllTop' onclick='process_check_management(this.id)'></td>");
                Response.Write("<td width='25%'>Tên</td>");
                Response.Write("<td width='40%'>Thông tin nhà sản xuất</td>");
                Response.Write("<td width='15%'></td>");
                Response.Write("<td width='15%'></td>");
                Response.Write("</tr>");

                int j = 1;
                String strSearch = '"' + "true" + '"';

                for (int i = iStart; i < iEnd; i++)
                {
                    if (j == 1)
                    {
                        Response.Write("<tr class='management_celllight1'>");
                        j = 0;
                    }
                    else
                    {
                        Response.Write("<tr class='management_celllight0'>");
                        j = 1;
                    }
                    Response.Write("<td align='center'><input type='checkbox' id='checkedIDList[]' name='checkedIDList[]' value='" + nsx_list[i].MaNhaSanXuat + "'/></td>");
                    Response.Write("<td align='left' style='padding: 5px;'>" + nsx_list[i].TenNhaSanXuat + "</td>");
                    Response.Write("<td align='left' style='padding: 5px;'>" + nsx_list[i].ThongTinNhaSanXuat + "</td>");
                    String strId = '"' + nsx_list[i].MaNhaSanXuat.ToString() + '"';
                    Response.Write("<td align='center' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_delete_manufacturer(" + strId + "," + strTotalrow + "," + strLimit + "," + strSearch + ");return false;'><span>Xóa</span></a>" +
                        "</div>" + "</td>");
                    Response.Write("<td align='center' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_update_manufacturer_getform(" + strId + ");return false;'><span>Cập nhật</span></a>"
                        + "</div>" + "</td>");
                    Response.Write("</tr>");
                }
                if (nsx_list.Count() > 0)
                {
                    Response.Write("<tr>" + "<td align='center'><input type='checkBox' id='checkAllBottom' onclick='process_check_management(this.id)'></td>");
                    Response.Write("<td align='left' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_delete_checked_manufacturer(" + strTotalrow + "," + strLimit + "," + strSearch + ");return false;'><span>Xóa chọn</span></a>"
                        + "</div>" + "</td>");
                    Response.Write("</tr>");
                }
                Response.Write("</tbody>");
                Response.Write("</table>");
                Response.Write("</div>"); /*end: div management_list */
                Response.Write("<div align='center'>");
                strContext = '"' + "previous" + '"';
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_manufacturer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Lùi</span></a>" +
                    "</div>");
                float fLimit = 10;
                double totalPage = Math.Ceiling(totalrow / fLimit);
                Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
                strContext = '"' + "next" + '"';
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_manufacturer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Tiếp</span></a>" +
                    "</div>");

                Response.Write("<div><select id=''>");
                strContext = '"' + "jump" + '"';
                for (int i = 1; i <= totalPage; i++)
                {
                    if (i == int.Parse(page))
                    {
                        Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                    }
                    else
                    {
                        strCount = '"' + i.ToString() + '"';
                        Response.Write("<option id='' value='" + i + "' onclick='ajax_search_manufacturer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                    }
                }
                Response.Write("</select></div>");/*end: select */
            }
        }

        public void add_new_manufacturer()
        {
            if (Request.QueryString["get_form"] != null)
            {
                String strContext = '"' + "default" + '"';
                String strTotalrow = '"' + "-1" + '"';
                String strLimit = '"' + "10" + '"';
                String strCount = '"' + "-1" + '"';
                Response.Write("<h4><a href='#' onclick='ajax_manage_manufacturer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
                Response.Write("<br/>");

                Response.Write("<div class='cmxform' id='update_manufacturer_form'>");
                Response.Write("<fieldset>");
                Response.Write("<legend>Thông tin loại sản phẩm</legend>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='name'>Tên</label>");
                Response.Write("<input id='name' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='info'>Thông tin</label>");
                Response.Write("<input id='info' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_add_new_manufacturer_process();return false;'><span>Thêm</span></a>" +
                    "</div>");
                Response.Write("</fieldset>");
                Response.Write("</div>"); /*end: div update_kinds_of_product_form */
            }
            else /* if (Request.QueryString["send_info"] != null) */
            {
                String name = "";
                if (Request.QueryString["name"] != null)
                {
                    name = Request.QueryString["name"];
                    if (name.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        name.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        name = name.Substring(1, name.Length - 2);
                    }
                }
                else
                {
                    return;
                }
                String info = "";
                if (Request.QueryString["info"] != null)
                {
                    info = Request.QueryString["info"];
                    if (info.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        info.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        info = info.Substring(1, info.Length - 2);
                    }
                }
                else
                {
                    return;
                }

                shop_nhasanxuat nsxLinq = new shop_nhasanxuat();
                nsxLinq.TenNhaSanXuat = name;
                nsxLinq.ThongTinNhaSanXuat = info;
                NhaSanXuatBUS nsx_BUS = new NhaSanXuatBUS();
                nsx_BUS.ThemNhaSanXuat(nsxLinq);
            }
        }

        //****************************************************************************************************
        // * SAN PHAM
        // ***************************************************************************************************

        public void manage_product()
        {
            String page = "";
            if (Request.QueryString["page"] == null)
            {
                return;
            }
            else
            {
                page = Request.QueryString["page"];
                if (page.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    page.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    page = page.Substring(1, page.Length - 2);
                }
            }

            String strPage = '"' + page + '"';
            SanPhamBUS sp_BUS = new SanPhamBUS();
            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            int iStart = (int.Parse(page) - 1) * iLimit;
            List<shop_sanpham> sp_list = sp_BUS.LaySanPhamGioiHan(iStart, iLimit);
            int totalrow = sp_BUS.LaySoLuongSanPham();
            String strTotalrow = '"' + totalrow.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            String strContext = "";

            Response.Write("<div id='content_management'>");
            Response.Write("<h1 id='management_title'>Quản lý sản phẩm</h1>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<table border='0'><tbody><tr><td>");
            Response.Write("<input type='text' id='key_search' size='50' maxlength='100'/></td><td>");
            Response.Write("<div class='art-button-wrapper' valign='bottom'>");
            Response.Write("<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_search_product(\"default\",\"-1\",\"10\",\"-1\");return false;'><span>Tìm kiếm</span></a>");
            Response.Write("</div>");
            Response.Write("</td></tr></tbody></table>");/*end: table tim_kiem */
            Response.Write("<div id='management_list'>");

            Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
            Response.Write("<tbody>");
            Response.Write("<tr class='management_table_header' style='text-align: center;'>");
            Response.Write("<td width='30%'>Tên</td>");
            Response.Write("<td width='50%'>Mô tả</td>");
            Response.Write("<td width='10%'></td>");
            Response.Write("<td width='10%'></td>");
            Response.Write("</tr>");

            int j = 1;
            String strSearch = '"' + "false" + '"';
            for (int i = 0; i < sp_list.Count(); i++)
            {
                if (j == 1)
                {
                    Response.Write("<tr class='management_celllight1'>");
                    j = 0;
                }
                else
                {
                    Response.Write("<tr class='management_celllight0'>");
                    j = 1;
                }
                Response.Write("<td align='left' style='padding: 5px;'>" + sp_list[i].TenSanPham + "</td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + sp_list[i].MoTa + "</td>");
                String strId = '"' + sp_list[i].MaSanPham.ToString() + '"';
                Response.Write("<td align='center' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_view_detail_product(" + strId + ");return false;'><span>Chi tiết</span></a>"
                    + "</div>" + "</td>");
                Response.Write("<td align='center' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_update_product_getform(" + strId + ");return false;'><span>Cập nhật</span></a>"
                    + "</div>" + "</td>");
                Response.Write("</tr>");
            }
            if (sp_list.Count() > 0)
            {
                Response.Write("<tr>");
                Response.Write("<td></td>");
                Response.Write("<td></td>");
                Response.Write("<td></td>");
                Response.Write("<td align='left' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' title='Thêm' onclick='ajax_add_new_product_getform();return false;'><span>Thêm</span></a>"
                    + "</div>" + "</td>");
                Response.Write("</tr>");
            }
            Response.Write("</tbody>");
            Response.Write("</table>");
            Response.Write("</div>"); /*end: div management_list */
            Response.Write("<div align='center'>");
            strContext = '"' + "previous" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Lùi</span></a>" +
                "</div>");
            float fLimit = 10;
            double totalPage = Math.Ceiling(totalrow / fLimit);
            Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
            strContext = '"' + "next" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Tiếp</span></a>" +
                "</div>");
            Response.Write("</div>"); /*end: div pageIndex */
            Response.Write("<div><select id=''>");
            strContext = '"' + "jump" + '"';
            for (int i = 1; i <= totalPage; i++)
            {
                if (i == int.Parse(page))
                {
                    Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                }
                else
                {
                    strCount = '"' + i.ToString() + '"';
                    Response.Write("<option id='' value='" + i + "' onclick='ajax_manage_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                }
            }
            Response.Write("</select></div>");/*end: select */
            Response.Write("</div>"); /*end: div content_management */
        }

        public void update_product()
        {
            if (Request.QueryString["get_form"] != null)
            {
                String id = "";
                if (Request.QueryString["id"] != null)
                {
                    id = Request.QueryString["id"];
                    if (id.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        id.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        id = id.Substring(1, id.Length - 2);
                    }
                }

                String key_search = "";
                if (Request.QueryString["key_search"] != null)
                {
                    key_search = Request.QueryString["key_search"];
                    if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        key_search.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        key_search = key_search.Substring(1, key_search.Length - 2);
                    }
                }

                String strID = '"' + id + '"';
                String strContext = '"' + "default" + '"';
                String strTotalrow = '"' + "-1" + '"';
                String strLimit = '"' + "10" + '"';
                String strCount = '"' + "-1" + '"';
                if (key_search.CompareTo("") == 0)
                {
                    Response.Write("<h4><a href='#' onclick='ajax_manage_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
                }
                else
                {
                    String strKeySearch = '"' + key_search + '"';
                    Response.Write("<h4><a href='#' onclick='ajax_search_product(" + strKeySearch + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
                }
                Response.Write("<br/>");

                SanPhamBUS sp_BUS = new SanPhamBUS();
                List<shop_sanpham> sp = sp_BUS.LaySanPhamTheoMa(int.Parse(id));
                Response.Write("<div class='cmxform' id='update_product_form'>");
                Response.Write("<fieldset>");
                Response.Write("<legend>Thông tin sản phẩm</legend>");
                Response.Write("<p>");
                Response.Write("<input type='hidden' id='product_id' value='" + strID + "'/>");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='name'>Tên</label>");
                Response.Write("<input id='name' value='" + sp[0].TenSanPham  + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='info'>Mô tả</label>");
                Response.Write("<input id='info' value='" + sp[0].MoTa   + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='price'>Đơn giá</label>");
                Response.Write("<input id='price' value='" + sp[0].DonGia   + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='exist'>Số lượng còn</label>");
                Response.Write("<input id='exist' value='" + sp[0].SoLuongCon   + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='input'>Số lượng nhập</label>");
                Response.Write("<input id='input' value='" + sp[0].SoLuongNhap   + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='gender'>Phái</label>");
                Response.Write("<select id='gender'>");
                for(int i=0; i< 2; i++)
                {
                    if (sp[0].Phai.Equals(i))
                    {
                        if (i == 0)
                        {
                            Response.Write("<option value='0' selected>Nữ</option>");
                        }
                        else
                        {
                            Response.Write("<option value='1' selected>Nam</option>");
                        }
                    }
                    else
                    {
                        if (i == 0)
                        {
                            Response.Write("<option value='0' >Nữ</option>");
                        }
                        else
                        {
                            Response.Write("<option value='1' >Nam</option>");
                        }
                    }
                }
                Response.Write("</select>");
                Response.Write("</p>");
                LoaiSanPhamBUS lsp_BUS = new LoaiSanPhamBUS();
                List<shop_loaisanpham> lsp_list = lsp_BUS.LayLoaiSanPham();
                Response.Write("<p align='left'>");
                Response.Write("<label for='name'>Loại sản phẩm</label>");
                Response.Write("<select id='kinds_of_product'>");
                for (int i = 0; i < lsp_list.Count(); i++)
                {
                    if (sp[0].MaLoaiSanPham == lsp_list[i].MaLoaiSanPham)
                    {
                        Response.Write("<option value='" + lsp_list[i].MaLoaiSanPham + "' selected>" + lsp_list[i] .TenLoaiSanPham+ "</option>");
                    }
                    else
                    {
                        Response.Write("<option value='" + lsp_list[i].MaLoaiSanPham + "'>" + lsp_list[i].TenLoaiSanPham + "</option>");
                    }
                }
                Response.Write("</select>");
                Response.Write("</p>");
                NhaSanXuatBUS nsx_BUS = new NhaSanXuatBUS();
                List<shop_nhasanxuat> nsx_list = nsx_BUS.LayDanhSachNhaSanXuat();
                Response.Write("<p align='left'>");
                Response.Write("<label for='name'>Nhà sản xuất</label>");
                Response.Write("<select id='manufacturer'>");
                for (int i = 0; i < nsx_list.Count(); i++)
                {
                    if (sp[0].MaNhaSanXuat == nsx_list[i].MaNhaSanXuat)
                    {
                        Response.Write("<option value='" + nsx_list[i].MaNhaSanXuat + "' selected>" + nsx_list[i].TenNhaSanXuat + "</option>");
                    }
                    else
                    {
                        Response.Write("<option value='" + nsx_list[i].MaNhaSanXuat + "'>" + nsx_list[i].TenNhaSanXuat + "</option>");
                    }
                }
                Response.Write("</select>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='size'>Kích cỡ</label>");
                Response.Write("<input id='size' value='" + sp[0].Size + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_update_product_process();return false;'><span>Cập nhật</span></a>" +
                    "</div>");
                Response.Write("</fieldset>");
                Response.Write("</div>"); /*end: div update_product */
            }
            else /* if (Request.QueryString["send_info"] != null) */
            {
                String id = "";
                if (Request.QueryString["id"] != null)
                {
                    id = Request.QueryString["id"];
                    if (id.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        id.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        id = id.Substring(1, id.Length - 2);
                    }
                }
                String name = "";
                if (Request.QueryString["name"] != null)
                {
                    name = Request.QueryString["name"];
                    if (name.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        name.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        name = name.Substring(1, name.Length - 2);
                    }
                }
                String info = "";
                if (Request.QueryString["info"] != null)
                {
                    info = Request.QueryString["info"];
                    if (info.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        info.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        info = info.Substring(1, info.Length - 2);
                    }
                }
                String price = "";
                if (Request.QueryString["price"] != null)
                {
                    price = Request.QueryString["price"];
                    if (price.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        price.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        price = price.Substring(1, price.Length - 2);
                    }
                }
                String exist = "";
                if (Request.QueryString["exist"] != null)
                {
                    exist = Request.QueryString["exist"];
                    if (exist.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        exist.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        exist = exist.Substring(1, exist.Length - 2);
                    }
                }
                String input = "";
                if (Request.QueryString["input"] != null)
                {
                    input = Request.QueryString["input"];
                    if (input.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        input.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        input = input.Substring(1, input.Length - 2);
                    }
                }
                String gender = "";
                if (Request.QueryString["gender"] != null)
                {
                    gender = Request.QueryString["gender"];
                    if (gender.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        gender.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        gender = gender.Substring(1, gender.Length - 2);
                    }
                }
                String kinds_of_product = "";
                if (Request.QueryString["kinds_of_product"] != null)
                {
                    kinds_of_product = Request.QueryString["kinds_of_product"];
                    if (kinds_of_product.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        kinds_of_product.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        kinds_of_product = kinds_of_product.Substring(1, kinds_of_product.Length - 2);
                    }
                }
                String manufacturer = "";
                if (Request.QueryString["manufacturer"] != null)
                {
                    manufacturer = Request.QueryString["manufacturer"];
                    if (manufacturer.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        manufacturer.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        manufacturer = manufacturer.Substring(1, manufacturer.Length - 2);
                    }
                }
                String size = "";
                if (Request.QueryString["size"] != null)
                {
                    size = Request.QueryString["size"];
                    if (size.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        size.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        size = size.Substring(1, size.Length - 2);
                    }
                }

                SanPhamBUS sp_BUS = new SanPhamBUS();
                List<shop_sanpham> spLinq = sp_BUS.LaySanPhamTheoMa(int.Parse(id));

                spLinq[0].TenSanPham = name;
                spLinq[0].MoTa = info;
                spLinq[0].DonGia = decimal.Parse(price);
                spLinq[0].SoLuongCon = (int)float.Parse(exist);
                spLinq[0].SoLuongNhap = (int)float.Parse(input);
                if (gender == "0")
                {
                    spLinq[0].Phai = false;
                }
                else
                {
                    spLinq[0].Phai = true;
                }
                spLinq[0].MaLoaiSanPham = int.Parse(kinds_of_product);
                spLinq[0].MaNhaSanXuat = int.Parse(manufacturer);
                spLinq[0].Size = size;

                sp_BUS.CapNhatSP(spLinq[0]);
            }
        }

        public void add_new_product()
        {
            if (Request.QueryString["get_form"] != null)
            {
                String strContext = '"' + "default" + '"';
                String strTotalrow = '"' + "-1" + '"';
                String strLimit = '"' + "10" + '"';
                String strCount = '"' + "-1" + '"';
                    Response.Write("<h4><a href='#' onclick='ajax_manage_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
                    Response.Write("<br/>");

                Response.Write("<div class='cmxform' id='update_product_form'>");
                Response.Write("<fieldset>");
                Response.Write("<legend>Thông tin sản phẩm</legend>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='name'>Tên</label>");
                Response.Write("<input id='name' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='info'>Mô tả</label>");
                Response.Write("<input id='info' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='price'>Đơn giá</label>");
                Response.Write("<input id='price' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='input'>Số lượng nhập</label>");
                Response.Write("<input id='input' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='gender'>Phái</label>");
                Response.Write("<select id='gender'>");
                for (int i = 0; i < 2; i++)
                {
                        if (i == 0)
                        {
                            Response.Write("<option value='0' >Nữ</option>");
                        }
                        else
                        {
                            Response.Write("<option value='1' >Nam</option>");
                        }
                }
                Response.Write("</select>");
                Response.Write("</p>");
                LoaiSanPhamBUS lsp_BUS = new LoaiSanPhamBUS();
                List<shop_loaisanpham> lsp_list = lsp_BUS.LayLoaiSanPham();
                Response.Write("<p align='left'>");
                Response.Write("<label for='kinds_of_product'>Loại sản phẩm</label>");
                Response.Write("<select id='kinds_of_product'>");
                for (int i = 0; i < lsp_list.Count(); i++)
                {
                        Response.Write("<option value='" + lsp_list[i].MaLoaiSanPham + "'>" + lsp_list[i].TenLoaiSanPham + "</option>");
                }
                Response.Write("</select>");
                Response.Write("</p>");
                NhaSanXuatBUS nsx_BUS = new NhaSanXuatBUS();
                List<shop_nhasanxuat> nsx_list = nsx_BUS.LayDanhSachNhaSanXuat();
                Response.Write("<p align='left'>");
                Response.Write("<label for='manufacturer'>Nhà sản xuất</label>");
                Response.Write("<select id='manufacturer'>");
                for (int i = 0; i < nsx_list.Count(); i++)
                {
                        Response.Write("<option value='" + nsx_list[i].MaNhaSanXuat + "'>" + nsx_list[i].TenNhaSanXuat + "</option>");
                }
                Response.Write("</select>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='size'>Kích cỡ</label>");
                Response.Write("<input id='size' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                Response.Write("</p>");
                Response.Write("<p align='left'>");
                Response.Write("<label for='size'>Chọn hình đại diện</label>");
                Response.Write("<iframe src ='WebForm1.aspx' width='100%' height='180px' style='border:0px solid #fff;'> <p>Your browser does not support iframes.</p> </iframe>");
                Response.Write("</p>");
                //Response.Write("<form id='frmUploadFile' action='controller.aspx?task=upload_img' method='post' enctype='multipart/form-data' target='upload_target' runat='server'><p align='left'>");
                //Response.Write("<label for='size'>Hình trước</label>");
                //Response.Write("<input type='file' style='border-style: dashed; border-color: rgb(204, 204, 204); height: 31px; width: 226px; margin-left: 0px;' id='img_forward' />");
                //Response.Write("</p>");
                //Response.Write("<p align='left'>");
                //Response.Write("<label for='size'>Hình sau</label>");
                //Response.Write("<input type='file' style='border-style: dashed; border-color: rgb(204, 204, 204); height: 31px; width: 226px; margin-left: 0px;' id='img_back' />");
                //Response.Write("</p>");
                //Response.Write("<p align='left'>");
                //Response.Write("<input type='submit' id='' />");
                //Response.Write("<iframe id='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px solid #fff;'></iframe>");
                //Response.Write("</p></form>");
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_add_new_product_process();return false;'><span>Thêm</span></a>" +
                    "</div>");
                Response.Write("</fieldset>");
                Response.Write("</div>"); /*end: div update_product */
            }
            else /* if (Request.QueryString["send_info"] != null) */
            {
                String name = "";
                if (Request.QueryString["name"] != null)
                {
                    name = Request.QueryString["name"];
                    if (name.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        name.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        name = name.Substring(1, name.Length - 2);
                    }
                }
                String info = "";
                if (Request.QueryString["info"] != null)
                {
                    info = Request.QueryString["info"];
                    if (info.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        info.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        info = info.Substring(1, info.Length - 2);
                    }
                }
                String price = "";
                if (Request.QueryString["price"] != null)
                {
                    price = Request.QueryString["price"];
                    if (price.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        price.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        price = price.Substring(1, price.Length - 2);
                    }
                }
                String input = "";
                if (Request.QueryString["input"] != null)
                {
                    input = Request.QueryString["input"];
                    if (input.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        input.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        input = input.Substring(1, input.Length - 2);
                    }
                }
                String gender = "";
                if (Request.QueryString["gender"] != null)
                {
                    gender = Request.QueryString["gender"];
                    if (gender.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        gender.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        gender = gender.Substring(1, gender.Length - 2);
                    }
                }
                String kinds_of_product = "";
                if (Request.QueryString["kinds_of_product"] != null)
                {
                    kinds_of_product = Request.QueryString["kinds_of_product"];
                    if (kinds_of_product.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        kinds_of_product.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        kinds_of_product = kinds_of_product.Substring(1, kinds_of_product.Length - 2);
                    }
                }
                String manufacturer = "";
                if (Request.QueryString["manufacturer"] != null)
                {
                    manufacturer = Request.QueryString["manufacturer"];
                    if (manufacturer.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        manufacturer.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        manufacturer = manufacturer.Substring(1, manufacturer.Length - 2);
                    }
                }
                String size = "";
                if (Request.QueryString["size"] != null)
                {
                    size = Request.QueryString["size"];
                    if (size.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        size.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        size = size.Substring(1, size.Length - 2);
                    }
                }

                shop_sanpham spLinq = new shop_sanpham();

                spLinq.TenSanPham = name;
                spLinq .MoTa = info;
                spLinq .DonGia = decimal.Parse(price);
                spLinq.SoLuongCon = (int)float.Parse(input);
                spLinq .SoLuongNhap = (int)float.Parse(input);
                if (gender == "0")
                {
                    spLinq .Phai = false;
                }
                else
                {
                    spLinq .Phai = true;
                }

                spLinq .MaLoaiSanPham = int.Parse(kinds_of_product);
                spLinq .MaNhaSanXuat = int.Parse(manufacturer);
                spLinq .Size = size;
                spLinq.NgayNhap = DateTime.Now;

                String strXml = "<Hinh>";
                if (EFashion.Employee.WebForm1.img_forward_img_name != "-1")
                {
                    strXml = strXml + "<HinhTruoc>~\\images\\SanPham\\" + EFashion.Employee.WebForm1.img_forward_img_name + "</HinhTruoc>";
                }
                if (EFashion.Employee.WebForm1.img_backward_img_name != "-1")
                {
                    strXml = strXml + "<HinhSau>~\\images\\SanPham\\" + EFashion.Employee.WebForm1.img_backward_img_name + "</HinhSau>";
                }
                strXml = strXml + "</Hinh>";

                spLinq.HinhSanPham = System.Xml.Linq.XElement.Parse(strXml);
                spLinq.KhuyenMai = System.Xml.Linq.XElement.Parse("<KhuyenMai />");

                SanPhamBUS sp_BUS = new SanPhamBUS();
                sp_BUS.ThemSanPham(spLinq);
            }
        }

        public void search_product()
        {
            String key_search = "";
            if (Request.QueryString["key_search"] == null)
            {
                return;
            }
            else
            {
                key_search = Request.QueryString["key_search"];
                if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    key_search.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    key_search = key_search.Substring(1, key_search.Length - 2);
                }
            }

            SanPhamBUS sp_BUS = new SanPhamBUS();
            List<shop_sanpham> sp_list = sp_BUS.LaySanPhamTheoKhoa(key_search);
            int totalrow = sp_list.Count();
            String strKeySearch = '"' + key_search + '"';
            String strContext = '"' + "default" + '"';
            String strTotalrow = '"' + totalrow.ToString() + '"';
            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            Response.Write("<h4><a href='#' onclick='ajax_manage_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            Response.Write("<br/>");

            if (sp_list.Count() == 0)
            {
                Response.Write("<h4>Không có dữ liệu sản phẩm nào thích hợp với từ khóa \"" + key_search + "\"</h4>");
            }
            else
            {
                String page = "";
                if (Request.QueryString["page"] == null)
                {
                    return;
                }
                else
                {
                    page = Request.QueryString["page"];
                    if (page.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        page.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        page = page.Substring(1, page.Length - 2);
                    }
                }

                String strPage = '"' + page + '"';
                int iStart = iLimit * (int.Parse(page) - 1);
                int iEnd = iLimit * int.Parse(page);
                if (iEnd > totalrow)
                {
                    iEnd = totalrow;
                }

                Response.Write("<div id='content_management'>");
                Response.Write("<h4 id='management_title'>Kết quả tìm kiếm sản phẩm với từ khóa \"" + key_search + "\"</h4>");
                Response.Write("<table border='0'><tbody><tr><td>");
                Response.Write("<input type='text' id='key_search' value='" + key_search + "' size='50' maxlength='100'/></td><td>");
                Response.Write("<div class='art-button-wrapper' valign='bottom'>");
                Response.Write("<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_product(\"default\",\"-1\",\"10\",\"-1\");return false;'><span>Tìm kiếm</span></a>");
                Response.Write("</div>");
                Response.Write("</td></tr></tbody></table>");/*end: table tim_kiem */
                Response.Write("<div id='management_list'>");

                Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
                Response.Write("<tbody>");
                Response.Write("<tr class='management_table_header' style='text-align: center;'>");
                Response.Write("<td width='30%'>Tên</td>");
                Response.Write("<td width='50%'>Mô tả</td>");
                Response.Write("<td width='10%'></td>");
                Response.Write("<td width='10%'></td>");
                Response.Write("</tr>");

                int j = 1;
                String strSearch = '"' + "true" + '"';

                for (int i = iStart; i < iEnd; i++)
                {
                    if (j == 1)
                    {
                        Response.Write("<tr class='management_celllight1'>");
                        j = 0;
                    }
                    else
                    {
                        Response.Write("<tr class='management_celllight0'>");
                        j = 1;
                    }
                    Response.Write("<td align='left' style='padding: 5px;'>" + sp_list[i].TenSanPham + "</td>");
                    Response.Write("<td align='left' style='padding: 5px;'>" + sp_list[i].MoTa + "</td>");
                    String strId = '"' + sp_list[i].MaSanPham.ToString() + '"';
                    Response.Write("<td align='center' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_view_detail_product(" + strId + ");return false;'><span>Chi tiết</span></a>"
                        + "</div>" + "</td>");
                    Response.Write("<td align='center' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_update_product_getform(" + strId + ");return false;'><span>Cập nhật</span></a>"
                        + "</div>" + "</td>");
                    Response.Write("</tr>");
                }
                if (sp_list.Count() > 0)
                {
                    Response.Write("<tr>");
                    Response.Write("<td></td>");
                    Response.Write("<td></td>");
                    Response.Write("<td></td>");
                    Response.Write("<td></td>");
                    Response.Write("<td></td>");
                    Response.Write("<td></td>");
                    Response.Write("<td></td>");
                    Response.Write("<td></td>");
                    Response.Write("<td></td>");
                    Response.Write("<td></td>");
                    Response.Write("<td></td>"); 
                    Response.Write("</tr>");
                }
                Response.Write("</tbody>");
                Response.Write("</table>");
                Response.Write("</div>"); /*end: div management_list */
                Response.Write("<div align='center'>");
                strContext = '"' + "previous" + '"';
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Lùi</span></a>" +
                    "</div>");
                float fLimit = 10;
                double totalPage = Math.Ceiling(totalrow / fLimit);
                Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
                strContext = '"' + "next" + '"';
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Tiếp</span></a>" +
                    "</div>");

                Response.Write("<div><select id=''>");
                strContext = '"' + "jump" + '"';
                for (int i = 1; i <= totalPage; i++)
                {
                    if (i == int.Parse(page))
                    {
                        Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                    }
                    else
                    {
                        strCount = '"' + i.ToString() + '"';
                        Response.Write("<option id='' value='" + i + "' onclick='ajax_search_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                    }
                }
                Response.Write("</select></div>");/*end: select */

            }
        }

        public void view_detail_product()
        {
            String id = "";
            if (Request.QueryString["id"] != null)
            {
                id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    id.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }
            }

            String key_search = "";
            if (Request.QueryString["key_search"] != null)
            {
                key_search = Request.QueryString["key_search"];
                if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    key_search.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    key_search = key_search.Substring(1, key_search.Length - 2);
                }
            }

            String strID = '"' + id + '"';
            String strContext = '"' + "default" + '"';
            String strTotalrow = '"' + "-1" + '"';
            String strLimit = '"' + "10" + '"';
            String strCount = '"' + "-1" + '"';
            if (key_search.CompareTo("") == 0)
            {
                Response.Write("<h4><a href='#' onclick='ajax_manage_product(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            }
            else
            {
                String strKeySearch = '"' + key_search + '"';
                Response.Write("<h4><a href='#' onclick='ajax_search_product(" + strKeySearch + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            }
            Response.Write("<br/>");

            SanPhamBUS sp_BUS = new SanPhamBUS();
            List<shop_sanpham> sp = sp_BUS.LaySanPhamTheoMa(int.Parse(id));
            Response.Write("<div class='cmxform' id='update_product_form'>");
            Response.Write("<fieldset>");
            Response.Write("<legend>Thông tin sản phẩm</legend>");
            Response.Write("<p>");
            Response.Write("<input type='hidden' id='product_id' value='" + strID + "'/>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label for='name'>Tên</label>");
            Response.Write("<input id='name' readonly='readonly'  value='" + sp[0].TenSanPham + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label for='info'>Mô tả</label>");
            Response.Write("<input id='info' readonly='readonly'  value='" + sp[0].MoTa + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label for='price'>Đơn giá</label>");
            Response.Write("<input id='price' readonly='readonly'  value='" + sp[0].DonGia + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
            Response.Write("</p>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label for='exist'>Số lượng còn</label>");
            Response.Write("<input id='exist' readonly='readonly'  value='" + sp[0].SoLuongCon + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label for='input'>Số lượng nhập</label>");
            Response.Write("<input id='input' readonly='readonly'  value='" + sp[0].SoLuongNhap + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label for='gender'>Phái</label>");
                if (sp[0].Phai == false)
                {
                    Response.Write("<input id='gender' readonly='readonly'  value='" + "Nữ" + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                }
                else
                {
                    Response.Write("<input id='gender' readonly='readonly'  value='" + "Nam" + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
                }            
            Response.Write("</p>");
            LoaiSanPhamBUS lsp_BUS = new LoaiSanPhamBUS();
            shop_loaisanpham lsp = lsp_BUS.LayLoaiSanPhamTheoMa(sp[0].MaLoaiSanPham);
            Response.Write("<p align='left'>");
            Response.Write("<label for='kinds_of_product'>Loại sản phẩm</label>");
            Response.Write("<input id='kinds_of_product' readonly='readonly'  value='" + lsp.TenLoaiSanPham + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
            Response.Write("</p>");
            NhaSanXuatBUS nsx_BUS = new NhaSanXuatBUS();
            shop_nhasanxuat nsx = nsx_BUS.LayNhaSanXuatsTheoMa(sp[0].MaNhaSanXuat);
            Response.Write("<p align='left'>");
            Response.Write("<label for='manufacturer'>Nhà sản xuất</label>");
            Response.Write("<input id='manufacturer' readonly='readonly'  value='" + nsx.TenNhaSanXuat + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
            Response.Write("<p align='left'>");
            Response.Write("<label for='size'>Kích cỡ</label>");
            Response.Write("<input id='size' readonly='readonly' value='" + sp[0].Size + "' size='40' maxlength='100' onkeyup='onKeyUpTextbox(this.id);' />");
            Response.Write("</p>");
            Response.Write("</fieldset>");
            Response.Write("</div>");
        }

        public void upload_img()
        {
            //if (img_forward.HasFile)
            //{
            //    //String filepath = img_forward.PostedFile.FileName;
            //    //String filename = Path.GetFileName(filepath);
            //    //img_forward.PostedFile.SaveAs(Server.MapPath("~/admin/images/upload/") + filename);
            //}
        }

        //**************************************************************************************************
        // * KHACH HANG
        // *************************************************************************************************

        public void manage_customer()
        {
            String page = "";
            if (Request.QueryString["page"] == null)
            {
                return;
            }
            else
            {
                page = Request.QueryString["page"];
                if (page.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    page.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    page = page.Substring(1, page.Length - 2);
                }
            }

            String strPage = '"' + page + '"';
            
            RoleBUS role_BUS = new RoleBUS();
            aspnet_Role role = role_BUS.LayRoleTheoLoweredRoleName("customer");
            UsersInRoleBUS uir_BUS = new UsersInRoleBUS();
            List<aspnet_UsersInRole> uir_list = uir_BUS.LayDanhSachTheoRoleID(role.RoleId);

            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            int totalrow = uir_list.Count();
            String strTotalrow = '"' + totalrow.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            String strContext = "";

            int iStart = (int.Parse(page) - 1) * iLimit;
            int iEnd = iLimit * int.Parse(page);
            if (iEnd > totalrow)
            {
                iEnd = totalrow;
            }

            Response.Write("<div id='content_management'>");
            Response.Write("<h1 id='management_title'>Quản lý khách hàng</h1>");
            Response.Write("<br/>");
            Response.Write("<table border='0'><tbody><tr><td>");
            Response.Write("<input type='text' id='key_search' size='50' maxlength='100'/></td><td>");
            Response.Write("<div class='art-button-wrapper' valign='bottom'>");
            Response.Write("<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_search_customer(\"default\",\"-1\",\"10\",\"-1\");return false;'><span>Tìm kiếm</span></a>");
            Response.Write("</div>");
            Response.Write("</td></tr></tbody></table>");/*end: table tim_kiem */
            Response.Write("<div id='management_list'>");

            Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
            Response.Write("<tbody>");
            Response.Write("<tr class='management_table_header' style='text-align: center;'>");
            Response.Write("<td width='35%'>Tài khoản</td>");
            Response.Write("<td width='25%'>Ngày tham gia</td>");
            Response.Write("<td width='25%'>Ngày đăng nhập gần nhất</td>");
            Response.Write("<td width='15%'></td>");
            //Response.Write("<td width='15%'></td>");
            Response.Write("</tr>");

            int j = 1;
            String strSearch = '"' + "false" + '"';
            UserBUS user_BUS = new UserBUS();
            MembershipBUS membership_BUS = new MembershipBUS();
            aspnet_User user = new aspnet_User();
            aspnet_Membership membership = new aspnet_Membership();

            for (int i = iStart; i < iEnd; i++)
            {
                user = user_BUS.LayUserTheoId(uir_list[i].UserId);
                membership = membership_BUS.LayTheoUserId(uir_list[i].UserId);
                String strID = '"' + uir_list[i].UserId.ToString()+ '"';

                if (j == 1)
                {
                    Response.Write("<tr class='management_celllight1'>");
                    j = 0;
                }
                else
                {
                    Response.Write("<tr class='management_celllight0'>");
                    j = 1;
                }
                Response.Write("<td align='left' style='padding: 5px;'>" + user.UserName + "</td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", membership.CreateDate) + "</td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", membership.LastLoginDate) + "</td>");
                Response.Write("<td align='center' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_view_detail_customer("+strID+");return false;'><span>Chi tiết</span></a>"
                    + "</div>" + "</td>");
                //Response.Write("<td align='center' style='padding: 5px;'>" +
                //    "<div class='art-button-wrapper'>" +
                //    "<span class='l'> </span>" +
                //    "<span class='r'> </span>" +
                //    "<a  class='art-button' href='#' onclick=';return false;'><span>Nhận xét</span></a>"
                //    + "</div>" + "</td>");
                Response.Write("</tr>");
            }
            Response.Write("</tbody>");
            Response.Write("</table>");
            Response.Write("</div>"); /*end: div management_list */

            Response.Write("<div align='center'>");
            strContext = '"' + "previous" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Lùi</span></a>" +
                "</div>");
            float fLimit = 10;
            double totalPage = Math.Ceiling(totalrow / fLimit);
            Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
            strContext = '"' + "next" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Tiếp</span></a>" +
                "</div>");
            Response.Write("</div>"); /*end: div pageIndex */
            Response.Write("<div><select id=''>");
            strContext = '"' + "jump" + '"';
            for (int i = 1; i <= totalPage; i++)
            {
                if (i == int.Parse(page))
                {
                    Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                }
                else
                {
                    strCount = '"' + i.ToString() + '"';
                    Response.Write("<option id='' value='" + i + "' onclick='ajax_manage_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                }
            }
            Response.Write("</select></div>");/*end: select */
            Response.Write("</div>"); /*end: div content_management */
        }

        public void view_detail_customer()
        {
            String id = "";
            if (Request.QueryString["id"] != null)
            {
                id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    id.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }
            }

            String key_search = "";
            if (Request.QueryString["key_search"] != null)
            {
                key_search = Request.QueryString["key_search"];
                if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    key_search.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    key_search = key_search.Substring(1, key_search.Length - 2);
                }
            }
            Guid guID = new Guid(id);
            UserBUS user_BUS = new UserBUS();
            MembershipBUS membership_BUS = new MembershipBUS();
            aspnet_User user = new aspnet_User();
            aspnet_Membership membership = new aspnet_Membership();

            user = user_BUS.LayUserTheoId(guID);
            membership = membership_BUS.LayTheoUserId(guID);

            String strID = '"' + id + '"';
            String strContext = '"' + "default" + '"';
            String strTotalrow = '"' + "-1" + '"';
            String strLimit = '"' + "10" + '"';
            String strCount = '"' + "-1" + '"';
            if (key_search.CompareTo("") == 0)
            {
                Response.Write("<h4><a href='#' onclick='ajax_manage_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            }
            else
            {
                String strKeySearch = '"' + key_search + '"';
                Response.Write("<h4><a href='#' onclick='ajax_search_customer(" + strKeySearch + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            }
            Response.Write("<br/>");

            Response.Write("<div class='cmxform' id='view_detail_customer_form'>");
            Response.Write("<fieldset>");
            Response.Write("<legend>Thông tin chi tiết khách hàng</legend>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Tài khoản</label>");
            Response.Write("<input type='text' value='"+user.UserName+"' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Email</label>");
            Response.Write("<input value='" + membership.LoweredEmail +"' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Địa chỉ</label>");
            Response.Write("<input value='" + membership.DiaChi +"' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Điện thoại</label>");
            Response.Write("<input value='" + membership.DTDD + "' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Ngày tham gia</label>");
            Response.Write("<input value='" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", membership.CreateDate) + "' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Ngày đăng nhập gần nhất</label>");
            Response.Write("<input value='" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", membership.LastLoginDate)+ "' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Website</label>");
            Response.Write("<input value='" + membership.Website+ "' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>YahooYM</label>");
            Response.Write("<input value='" + membership.YahooYM+ "' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Điểm tích lũy</label>");
            Response.Write("<input value='" + membership.DiemTichLuy+ "' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("</fieldset>");
            Response.Write("</div>"); /*end: div update_customer */
        }

        public void search_customer()
        {
            String key_search = "";
            if (Request.QueryString["key_search"] == null)
            {
                return;
            }
            else
            {
                key_search = Request.QueryString["key_search"];
                if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    key_search.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    key_search = key_search.Substring(1, key_search.Length - 2);
                }
            }

            UserBUS user_BUS = new UserBUS();
            List<aspnet_User> user_list = user_BUS.TimUserTheo_Khoa_LoweredRoleName(key_search, "customer ");

            int totalrow = user_list.Count();
            String strKeySearch = '"' + key_search + '"';
            String strContext = '"' + "default" + '"';
            String strTotalrow = '"' + totalrow.ToString() + '"';
            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            Response.Write("<h4><a href='#' onclick='ajax_manage_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            Response.Write("<br/>");

            if (user_list.Count() == 0)
            {
                Response.Write("<h4>Không có dữ liệu khách hàng nào thích hợp với từ khóa \"" + key_search + "\"</h4>");
            }
            else
            {
                String page = "";
                if (Request.QueryString["page"] == null)
                {
                    return;
                }
                else
                {
                    page = Request.QueryString["page"];
                    if (page.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        page.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        page = page.Substring(1, page.Length - 2);
                    }
                }

                String strPage = '"' + page + '"';
                int iStart = iLimit * (int.Parse(page) - 1);
                int iEnd = iLimit * int.Parse(page);
                if (iEnd > totalrow)
                {
                    iEnd = totalrow;
                }

                Response.Write("<div id='content_management'>");
                Response.Write("<h4 id='management_title'>Kết quả tìm kiếm khách hàng với từ khóa \"" + key_search + "\"</h4>");
                Response.Write("<table border='0'><tbody><tr><td>");
                Response.Write("<input type='text' id='key_search' value='" + key_search + "' size='50' maxlength='100'/></td><td>");
                Response.Write("<div class='art-button-wrapper' valign='bottom'>");
                Response.Write("<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_customer(\"default\",\"-1\",\"10\",\"-1\");return false;'><span>Tìm kiếm</span></a>");
                Response.Write("</div>");
                Response.Write("</td></tr></tbody></table>");/*end: table tim_kiem */
                Response.Write("<div id='management_list'>");

                Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
                Response.Write("<tbody>");
                Response.Write("<tr class='management_table_header' style='text-align: center;'>");
                Response.Write("<td width='35%'>Tài khoản</td>");
                Response.Write("<td width='25%'>Ngày tham gia</td>");
                Response.Write("<td width='25%'>Ngày đăng nhập gần nhất</td>");
                Response.Write("<td width='15%'></td>");
                //Response.Write("<td width='15%'></td>");
                Response.Write("</tr>");

                int j = 1;
                String strSearch = '"' + "true" + '"';
                MembershipBUS membership_BUS = new MembershipBUS();
                aspnet_Membership membership = new aspnet_Membership();

                for (int i = iStart; i < iEnd; i++)
                {
                    membership = membership_BUS.LayTheoUserId(user_list[i].UserId);
                    String strID = '"' + user_list[i].UserId.ToString() + '"';

                    if (j == 1)
                    {
                        Response.Write("<tr class='management_celllight1'>");
                        j = 0;
                    }
                    else
                    {
                        Response.Write("<tr class='management_celllight0'>");
                        j = 1;
                    }
                    Response.Write("<td align='left' style='padding: 5px;'>" + user_list[i].UserName + "</td>");
                    Response.Write("<td align='left' style='padding: 5px;'>" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", membership.CreateDate) + "</td>");
                    Response.Write("<td align='left' style='padding: 5px;'>" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", membership.LastLoginDate) + "</td>");

                    Response.Write("<td align='center' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_view_detail_customer(" + strID + ");return false;'><span>Chi tiết</span></a>"
                        + "</div>" + "</td>");
                    //Response.Write("<td align='center' style='padding: 5px;'>" +
                    //    "<div class='art-button-wrapper'>" +
                    //    "<span class='l'> </span>" +
                    //    "<span class='r'> </span>" +
                    //    "<a  class='art-button' href='#' onclick=';return false;'><span>Nhận xét</span></a>"
                    //    + "</div>" + "</td>");
                    Response.Write("</tr>");
                }
                Response.Write("</tbody>");
                Response.Write("</table>");
                Response.Write("</div>"); /*end: div management_list */

                Response.Write("<div align='center'>");
                strContext = '"' + "previous" + '"';
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Lùi</span></a>" +
                    "</div>");
                float fLimit = 10;
                double totalPage = Math.Ceiling(totalrow / fLimit);
                Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
                strContext = '"' + "next" + '"';
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Tiếp</span></a>" +
                    "</div>");
                Response.Write("</div>"); /*end: div pageIndex */
                Response.Write("<div><select id=''>");
                strContext = '"' + "jump" + '"';
                for (int i = 1; i <= totalPage; i++)
                {
                    if (i == int.Parse(page))
                    {
                        Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                    }
                    else
                    {
                        strCount = '"' + i.ToString() + '"';
                        Response.Write("<option id='' value='" + i + "' onclick='ajax_search_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                    }
                }
                Response.Write("</select></div>");/*end: select */
                Response.Write("</div>"); /*end: div content_management */
            }
            
        }

        //public void view_all_comments_of_customer()
        //{
        //    String id = "";
        //    if (Request.QueryString["id"] != null)
        //    {
        //        id = Request.QueryString["id"];
        //        if (id.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
        //            id.Substring(0, 1).ToString().CompareTo("\'") == 0)
        //        {
        //            id = id.Substring(1, id.Length - 2);
        //        }
        //    }

        //    String key_search = "";
        //    if (Request.QueryString["key_search"] != null)
        //    {
        //        key_search = Request.QueryString["key_search"];
        //        if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
        //            key_search.Substring(0, 1).ToString().CompareTo("\'") == 0)
        //        {
        //            key_search = key_search.Substring(1, key_search.Length - 2);
        //        }
        //    }
        //    Guid guID = new Guid(id);
        //    NhanXetBUS nx_BUS = new NhanXetBUS();
        //    List<shop_comment> nx_list = nx_BUS.LayNhanXetTheoMaKhachHang_NgayTaoGiamDan(guID);

        //    String strID = '"' + id + '"';
        //    String strContext = '"' + "default" + '"';
        //    String strTotalrow = '"' + "-1" + '"';
        //    String strLimit = '"' + "10" + '"';
        //    String strCount = '"' + "-1" + '"';
        //    if (key_search.CompareTo("") == 0)
        //    {
        //        Response.Write("<h1><a href='#' onclick='ajax_manage_customer(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h1>");
        //    }
        //    else
        //    {
        //        String strKeySearch = '"' + key_search + '"';
        //        Response.Write("<h1><a href='#' onclick='ajax_search_customer(" + strKeySearch + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h1>");
        //    }
        //    Response.Write("<br/>");

        //    int totalrow = nx_list.Count();
        //    String strTotalrow = '"' + totalrow.ToString() + '"';
        //    String strCount = '"' + "-1" + '"';
        //    String strContext = "";
        //    int iStart = iLimit * (int.Parse(page) - 1);
        //    int iEnd = iLimit * int.Parse(page);
        //    if (iEnd > totalrow)
        //    {
        //        iEnd = totalrow;
        //    }

        //    Response.Write("<div id='content_management'>");
        //    Response.Write("<h1 id='management_title'>Quản lý nhận xét</h1>");
        //    Response.Write("<div id='management_list'>");

        //    Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
        //    Response.Write("<tbody>");
        //    Response.Write("<tr class='management_table_header' style='text-align: center;'>");
        //    Response.Write("<td width='5%' align='center'><input type='checkBox' id='checkAllTop' onclick='process_check_management(this.id)'></td>");
        //    Response.Write("<td width='25%'>Sản phẩm</td>");
        //    Response.Write("<td width='20%'>Ngày tạo</td>");
        //    Response.Write("<td width='20%'>Khách hàng</td>");
        //    Response.Write("<td width='10%'></td>");
        //    Response.Write("<td width='10%'></td>");
        //    Response.Write("<td width='10%'></td>");
        //    Response.Write("</tr>");
        //}

        //******************************************************************************************************
        // * NHAN XET
        // *****************************************************************************************************

        public void manage_comment()
        {
            String page = "";
            if (Request.QueryString["page"] == null)
            {
                return;
            }
            else
            {
                page = Request.QueryString["page"];
                if (page.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    page.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    page = page.Substring(1, page.Length - 2);
                }
            }

            String strPage = '"' + page + '"';
            NhanXetBUS nx_BUS = new NhanXetBUS();
            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            List<shop_comment> nx_list = nx_BUS.LayDanhSach_NgayTaoGiamDan();
            int totalrow = nx_list.Count();
            String strTotalrow = '"' + totalrow.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            String strContext = "";
            int iStart = iLimit * (int.Parse(page) - 1);
            int iEnd = iLimit * int.Parse(page);
            if (iEnd > totalrow)
            {
                iEnd = totalrow;
            }

            Response.Write("<div id='content_management'>");
            Response.Write("<h1 id='management_title'>Quản lý nhận xét</h1>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<div id='management_list'>");

            Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
            Response.Write("<tbody>");
            Response.Write("<tr class='management_table_header' style='text-align: center;'>");
            Response.Write("<td width='5%' align='center'><input type='checkBox' id='checkAllTop' onclick='process_check_management(this.id)'></td>");
            Response.Write("<td width='25%'>Sản phẩm</td>");
            Response.Write("<td width='20%'>Ngày tạo</td>");
            Response.Write("<td width='20%'>Khách hàng</td>");
            Response.Write("<td width='10%'></td>");
            Response.Write("<td width='10%'></td>");
            Response.Write("<td width='10%'></td>");
            Response.Write("</tr>");

            int j = 1;
            SanPhamBUS sp_BUS = new SanPhamBUS();
            List<shop_sanpham> sp;
            UserBUS user_BUS = new UserBUS();
            aspnet_User user = new aspnet_User();
            String strSearch = '"' + "false" + '"';

            for (int i = iStart; i < iEnd; i++)
            {
                if (j == 1)
                {
                    Response.Write("<tr class='management_celllight1'>");
                    j = 0;
                }
                else
                {
                    Response.Write("<tr class='management_celllight0'>");
                    j = 1;
                }
                Response.Write("<td align='center'><input type='checkbox' id='checkedIDList[]' name='checkedIDList[]' value='" + nx_list[i].MaComment + "'/></td>");
                sp = sp_BUS.LaySanPhamTheoMa(nx_list[i].MaSanPham);
                Response.Write("<td align='left' style='padding: 5px;'>" + sp[0].TenSanPham + "</td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", nx_list[i].NgayTao) + "</td>");
                user = user_BUS.LayUserTheoId(nx_list[i].UserId);
                Response.Write("<td align='left' style='padding: 5px;'>" + user.UserName + "</td>");
                String strId = '"' + nx_list[i].MaComment.ToString() + '"';
                Response.Write("<td align='center' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_view_detail_comment("+strId+");return false;'><span>Chi tiết</span></a>" +
                    "</div>" + "</td>");
                Response.Write("<td align='center' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' title='Xóa' onclick='ajax_delete_comment(" + strId + "," + strTotalrow + "," + strLimit + "," + strSearch + ");return false;'><span>Xóa</span></a>" +
                    "</div>" + "</td>");
                if (nx_list[i].TrangThai == true)
                {
                    Response.Write("<td></td>");
                }
                else
                {
                    Response.Write("<td align='center' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_accept_comment(" + strId + "," + strTotalrow + "," + strLimit + ");return false;'><span>Duyệt</span></a>"
                        + "</div>" + "</td>");
                }
                Response.Write("</tr>");
            }
            if (nx_list.Count() > 0)
            {
                Response.Write("<tr>" + "<td align='center'><input type='checkBox' id='checkAllBottom' onclick='process_check_management(this.id)'></td>");
                Response.Write("<td align='left' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' title='Xóa' onclick='ajax_delete_checked_comment(" + strTotalrow + "," + strLimit + "," + strSearch + ");return false;'><span>Xóa chọn</span></a>"
                    + "</div>" + "</td>");
                Response.Write("<td></td>");
                Response.Write("<td></td>");
                Response.Write("<td></td>");
                Response.Write("<td></td>");
                Response.Write("<td></td>");
                Response.Write("</tr>");
            }
            Response.Write("</tbody>");
            Response.Write("</table>");
            Response.Write("</div>"); /*end: div management_list */

            Response.Write("<div align='center'>");
            strContext = '"' + "previous" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_comment(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Lùi</span></a>" +
                "</div>");
            float fLimit = 10;
            double totalPage = Math.Ceiling(totalrow / fLimit);
            Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
            strContext = '"' + "next" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_comment(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Tiếp</span></a>" +
                "</div>");
            Response.Write("</div>"); /*end: div pageIndex */
            Response.Write("<div><select id=''>");
            strContext = '"' + "jump" + '"';
            for (int i = 1; i <= totalPage; i++)
            {
                if (i == int.Parse(page))
                {
                    Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                }
                else
                {
                    strCount = '"' + i.ToString() + '"';
                    Response.Write("<option id='' value='" + i + "' onclick='ajax_manage_comment(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                }
            }
            Response.Write("</select></div>");/*end: select */
            Response.Write("</div>"); /*end: div content_management */
        }

        public void view_detail_comment()
        {
            String id = "";
            if (Request.QueryString["id"] != null)
            {
                id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    id.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }
            }

            NhanXetBUS nx_BUS = new NhanXetBUS();
            shop_comment nx = new shop_comment();
            nx = nx_BUS.LayNhanXetTheoMa(int.Parse(id));

            SanPhamBUS sp_BUS = new SanPhamBUS();
            List<shop_sanpham> sp = sp_BUS.LaySanPhamTheoMa(nx.MaSanPham);
            UserBUS user_BUS = new UserBUS();
            aspnet_User user = user_BUS.LayUserTheoId(nx.UserId);

            String strID = '"' + id + '"';
            String strContext = '"' + "default" + '"';
            String strTotalrow = '"' + "-1" + '"';
            String strLimit = '"' + "10" + '"';
            String strCount = '"' + "-1" + '"';

            Response.Write("<h4><a href='#' onclick='ajax_manage_comment(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            Response.Write("<br/>");

            Response.Write("<div class='cmxform' id='view_detail_customer_form'>");
            Response.Write("<fieldset>");
            Response.Write("<legend>Thông tin chi tiết nhận xét</legend>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Sản phẩm</label>");
            Response.Write("<input value='" + sp[0].TenSanPham + "' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Khách hàng</label>");
            Response.Write("<input value='" + user.UserName + "' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Nội dung</label>");
            Response.Write("<textarea readonly='readonly' cols='25'>"+nx.NoiDung+"</textarea>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Ngày tạo</label>");
            Response.Write("<input value='" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", nx.NgayTao) + "' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Tình trạng</label>");
            if(nx.TrangThai == true)
            {
                Response.Write("<input value='đã duyệt' readonly='readonly' size='40' maxlength='100'/>");
            }
            else
            {
                Response.Write("<input value='chưa duyệt' readonly='readonly' size='40' maxlength='100'/>");
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_accept_comment(" + strID + "," + strTotalrow + "," + strLimit + ");return false;'><span>Duyệt</span></a>" +
                    "</div>");
            }
            Response.Write("</fieldset>");
            Response.Write("</div>"); /*end: div update_customer */
        }

        public void accept_comment()
        {
            String id = "";
            if (Request.QueryString["id"] != null)
            {
                id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    id.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }
            }
            else
            {
                return;
            }

            int iID = int.Parse(id);
            NhanXetBUS nx_BUS = new NhanXetBUS();
            nx_BUS.CapNhatTrangThaiNX(iID,true);
        }

        public void delete_comment()
        {
            String id = "";
            if (Request.QueryString["id"] != null)
            {
                id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    id.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }
            }
            else
            {
                return;
            }

            int iID = int.Parse(id);
            NhanXetBUS nx_BUS = new NhanXetBUS();
            nx_BUS.XoaNhanXet(iID);
        }

        public void delete_checked_comment()
        {
            String checkedIDList = "";
            if (Request.QueryString["checkedIDList"] != null)
            {
                checkedIDList = Request.QueryString["checkedIDList"];
                if (checkedIDList.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    checkedIDList.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    checkedIDList = checkedIDList.Substring(1, checkedIDList.Length - 2);
                }
            }
            else
            {
                return;
            }
            String[] arrCheckedID = checkedIDList.Split(',');
            int count = arrCheckedID.Count();
            int iID = -1;
            NhanXetBUS nx_BUS = new NhanXetBUS();
            for (int i = 0; i < count; i++)
            {
                iID = int.Parse(arrCheckedID[i]);
                nx_BUS.XoaNhanXet(iID);
            }
        }

        //*****************************************************************************************************
        // * HOA DON
        // ****************************************************************************************************

        public void manage_bill()
        {
            String page = "";
            if (Request.QueryString["page"] == null)
            {
                return;
            }
            else
            {
                page = Request.QueryString["page"];
                if (page.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    page.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    page = page.Substring(1, page.Length - 2);
                }
            }

            String strPage = '"' + page + '"';

            HoaDonBUS hd_BUS = new HoaDonBUS();
            List<shop_hoadon> hd_list = hd_BUS.LayDanhSach_NgayTaoGiamDan();

            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            int totalrow = hd_list.Count();
            String strTotalrow = '"' + totalrow.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            String strContext = "";

            int iStart = (int.Parse(page) - 1) * iLimit;
            int iEnd = iLimit * int.Parse(page);
            if (iEnd > totalrow)
            {
                iEnd = totalrow;
            }

            Response.Write("<div id='content_management'>");
            Response.Write("<h1 id='management_title'>Quản lý hóa đơn</h1>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<br/>");
            Response.Write("<table border='0'><tbody><tr><td>"); /* lua chon */
            Response.Write("<span id='span_search_day'></span>&nbsp;&nbsp;");
            Response.Write("<input id='search_month' type='checkbox' onclick='check_search_month(this.id)' /> Tháng&nbsp;");
            Response.Write("</td>");
            Response.Write("</tr>");
            Response.Write("<tr>Từ: "); /* the hien select Từ*/
            Response.Write("<td>");
            Response.Write("<span id='span_show_day_from'></span>");
            Response.Write("<span id='span_show_month_from'></span>");
            Response.Write("năm <select id='value_search_year_from'>");
            int year_now = DateTime.Now.Year;
            for(int i=1970; i<=year_now; i++)
            {
                if (i == year_now)
                {
                    Response.Write("<option selected value='" + i + "'>" + i + "</option>");
                }
                else
                {
                    Response.Write("<option value='" + i + "'>" + i + "</option>");
                }
            }
            Response.Write("</select>&nbsp;&nbsp;");
            Response.Write("</td>");
            Response.Write("</tr>");
            Response.Write("<tr>Đến: "); /* the hien select Đến*/
            Response.Write("<td>");
            Response.Write("<span id='span_show_day_to'></span>");
            Response.Write("<span id='span_show_month_to'></span>");
            Response.Write("năm <select id='value_search_year_to'>");
            for (int i = 1970; i <= year_now; i++)
            {
                if (i == year_now)
                {
                    Response.Write("<option selected value='" + i + "'>" + i + "</option>");
                }
                else
                {
                    Response.Write("<option value='" + i + "'>" + i + "</option>");
                }
            }
            Response.Write("</select>&nbsp;&nbsp;");
            Response.Write("</td>");
            Response.Write("</tr>");
            Response.Write("<tr>"); /* nut tim kiem */
            Response.Write("<td>"); 
            Response.Write("<div class='art-button-wrapper' valign='bottom'>");
            Response.Write("<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_search_bill(\"default\",\"-1\",\"10\",\"-1\",\"-1\");return false;'><span>Tìm kiếm</span></a>");
            Response.Write("</div>");
            Response.Write("</td></tr></tbody></table>");/*end: table tim_kiem */
            Response.Write("<div id='management_list'>");

            Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
            Response.Write("<tbody>");
            Response.Write("<tr class='management_table_header' style='text-align: center;'>");
            Response.Write("<td width='30%'>Khách hàng</td>");
            Response.Write("<td width='20%'>Ngày mua</td>");
            Response.Write("<td width='20%'>Tổng tiền</td>");
            Response.Write("<td width='15%'></td>");
            Response.Write("<td width='15%'></td>");
            Response.Write("</tr>");

            int j = 1;
            String strSearch = '"' + "false" + '"';
            UserBUS user_BUS = new UserBUS();
            aspnet_User user = new aspnet_User();

            for (int i = iStart; i < iEnd; i++)
            {
                String strID = '"' + hd_list[i].MaHoaDon.ToString() + '"';

                if (j == 1)
                {
                    Response.Write("<tr class='management_celllight1'>");
                    j = 0;
                }
                else
                {
                    Response.Write("<tr class='management_celllight0'>");
                    j = 1;
                }
                if (hd_list[i].UserId.ToString() != "" && hd_list[i].UserId.ToString() != null)
                {
                    String strTmp = hd_list[i].UserId.ToString();
                    Guid guID = new Guid(strTmp);
                    user = user_BUS.LayUserTheoId(guID);
                    Response.Write("<td align='left' style='padding: 5px;'>" + user.UserName + "</td>");
                }
                else
                {
                    Response.Write("<td></td>");
                }
                Response.Write("<td align='center' style='padding: 5px;'>" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", hd_list[i].NgayLap) + "</td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + hd_list[i].ThanhTien + "</td>");
                Response.Write("<td align='center' style='padding: 5px;'>" +
                    "<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_view_detail_bill(" + strID + ");return false;'><span>Chi tiết</span></a>"
                    + "</div>" + "</td>");
                if (hd_list[i].TinhTrang == false)
                {
                    Response.Write("<td align='center' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_accept_bill(" + strID + "," + strTotalrow + "," + strLimit + ");return false;'><span>Duyệt</span></a>"
                        + "</div>" + "</td>");
                }
                else
                {
                    Response.Write("<td></td>");
                }
                Response.Write("</tr>");
            }
            Response.Write("</tbody>");
            Response.Write("</table>");
            Response.Write("</div>"); /*end: div management_list */

            Response.Write("<div align='center'>");
            strContext = '"' + "previous" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_bill(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Lùi</span></a>" +
                "</div>");
            float fLimit = 10;
            double totalPage = Math.Ceiling(totalrow / fLimit);
            Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
            strContext = '"' + "next" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_bill(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'><span>Tiếp</span></a>" +
                "</div>");
            Response.Write("</div>"); /*end: div pageIndex */
            Response.Write("<div><select id=''>");
            strContext = '"' + "jump" + '"';
            for (int i = 1; i <= totalPage; i++)
            {
                if (i == int.Parse(page))
                {
                    Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                }
                else
                {
                    strCount = '"' + i.ToString() + '"';
                    Response.Write("<option id='' value='" + i + "' onclick='ajax_manage_bill(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                }
            }
            Response.Write("</select></div>");/*end: select */
            Response.Write("</div>"); /*end: div content_management */
        }

        public void view_detail_bill()
        {
            String id = "";
            if (Request.QueryString["id"] != null)
            {
                id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    id.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }
            }

            //String key_search = "";
            //if (Request.QueryString["key_search"] != null)
            //{
            //    key_search = Request.QueryString["key_search"];
            //    if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
            //        key_search.Substring(0, 1).ToString().CompareTo("\'") == 0)
            //    {
            //        key_search = key_search.Substring(1, key_search.Length - 2);
            //    }
            //}

            HoaDonBUS hd_BUS = new HoaDonBUS();
            shop_hoadon hd = hd_BUS.LayHoaDonsTheoMa(int.Parse(id));

            ChiTietHoaDonBUS cthd_BUS = new ChiTietHoaDonBUS();
            List<shop_chitiethoadon> cthd_list = cthd_BUS.LayDanhSachTheoMaHoaDon(int.Parse(id));

            String strID = '"' + id + '"';
            String strContext = '"' + "default" + '"';
            String strTotalrow = '"' + "-1" + '"';
            String strLimit = '"' + "10" + '"';
            String strCount = '"' + "-1" + '"';
            //if (key_search.CompareTo("") == 0)
            //{
                Response.Write("<h4><a href='#' onclick='ajax_manage_bill(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            //}
            //else
            //{
            //    String strKeySearch = '"' + key_search + '"';
            //    Response.Write("<h4><a href='#' onclick='ajax_search_bill(" + strKeySearch + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            //}
            Response.Write("<br/>");

            Response.Write("<div class='cmxform' id='view_detail_bill_form'>");
            Response.Write("<fieldset>");
            Response.Write("<legend>Thông tin chi tiết hóa đơn</legend>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Khách hàng</label>");
            if (hd.UserId.ToString() != "" && hd.UserId.ToString() != null)
            {
                String strTmp = hd.UserId.ToString();
                Guid guID = new Guid(strTmp);
                UserBUS user_BUS = new UserBUS();
                aspnet_User user = user_BUS.LayUserTheoId(guID);
                Response.Write("<input type='text' value='" + user.UserName + "' readonly='readonly' size='40' maxlength='100'/>");
            }
            else
            {
                Response.Write("<input type='text' value='' readonly='readonly' size='40' maxlength='100'/>");
            }
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Ngày mua</label>");
            Response.Write("<input value='" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", hd.NgayLap) + "' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            //Response.Write("<p align='left'>");
            Response.Write("<div id='management_list'>");
            Response.Write("<label>Chi tiết</label>");
            /* begin:  table chi tiet hoa don */
            Response.Write("<table class='management_table' width='400px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
            Response.Write("<tbody>");
            Response.Write("<tr class='management_table_header' style='text-align: center;'>");
            Response.Write("<td width='40%'>Sản phẩm</td>");
            Response.Write("<td width='10%'>Số lượng</td>");
            Response.Write("<td width='25%'>Đơn giá</td>");
            Response.Write("<td width='25%'>Thành tiền</td>");
            Response.Write("</tr>");

            int iStart = 0;
            int iEnd = cthd_list.Count();
            int j = 1;
            SanPhamBUS sp_BUS = new SanPhamBUS();
            List<shop_sanpham> sp = new List<shop_sanpham>();

            for (int i = iStart; i < iEnd; i++)
            {
                sp = sp_BUS.LaySanPhamTheoMa(int.Parse(cthd_list[i].MaSanPham));
                if (j == 1)
                {
                    Response.Write("<tr class='management_celllight1'>");
                    j = 0;
                }
                else
                {
                    Response.Write("<tr class='management_celllight0'>");
                    j = 1;
                }
                Response.Write("<td align='left' style='padding: 5px;'>" + sp[0].TenSanPham + "</td>");
                Response.Write("<td align='center' style='padding: 5px;'>" + cthd_list[i].SoLuong + "</td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + cthd_list[i].DonGia + "</td>");
                if (cthd_list[i].DonGia != null)
                {
                    String tmp = cthd_list[i].DonGia.ToString();
                    decimal tong = cthd_list[i].SoLuong * decimal.Parse(tmp);
                    Response.Write("<td align='left' style='padding: 5px;'>" + tong.ToString() + "</td>");
                }
                else
                {
                    Response.Write("<td align='left' style='padding: 5px;'></td>");
                }
                Response.Write("</tr>");
            }
            Response.Write("</tbody>");
            Response.Write("</table>");
            Response.Write("</div>"); /*end: div management_list */
            /* end:  table chi tiet hoa don */
            //Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("</p>");
            Response.Write("<p align='left'>");
            Response.Write("<label>Tổng tiền</label>");
            Response.Write("<input value='" + hd.ThanhTien + "' readonly='readonly' size='40' maxlength='100'/>");
            Response.Write("</p>");
            Response.Write("</fieldset>");
            Response.Write("</div>"); /*end: div update_customer */
        }

        public void accept_bill()
        {
            String id = "";
            if (Request.QueryString["id"] != null)
            {
                id = Request.QueryString["id"];
                if (id.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    id.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    id = id.Substring(1, id.Length - 2);
                }
            }
            else
            {
                return;
            }

            int iID = int.Parse(id);
            HoaDonBUS hd_BUS = new HoaDonBUS();
            hd_BUS.CapNhatTinhTrangHoaDon(iID);
        }

        public void search_bill()
        {
            String key_search = "";
            if (Request.QueryString["key_search"] == null)
            {
                return;
            }
            else
            {
                key_search = Request.QueryString["key_search"];
                if (key_search.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    key_search.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    key_search = key_search.Substring(1, key_search.Length - 2);
                }
            }
            String strKeySearch = '"' +key_search+ '"';

            String[] arrKeySearch = key_search.Split(',');
            DateTime date_start = new DateTime();
            DateTime date_end = new DateTime();
            if(arrKeySearch.Count() == 2)
            {
                date_start = new DateTime(int.Parse(arrKeySearch[0]), 1, 1);
                date_end = new DateTime(int.Parse(arrKeySearch[1]), 12, 31);
            }
            if (arrKeySearch.Count() == 4)
            {
                date_start = new DateTime(int.Parse(arrKeySearch[0]), int.Parse(arrKeySearch[1]),1);
                
                if (arrKeySearch[3] == "1" || arrKeySearch[3] == "3" || arrKeySearch[3] == "5" || arrKeySearch[3] == "7" ||
                        arrKeySearch[3] == "8" || arrKeySearch[3] == "10" || arrKeySearch[3] == "12")
                {
                    date_end = new DateTime(int.Parse(arrKeySearch[2]), int.Parse(arrKeySearch[3]), 31);
                }
                if (arrKeySearch[3] == "4" || arrKeySearch[3] == "6" || arrKeySearch[3] == "9" ||
                        arrKeySearch[3] == "11")
                {
                    date_end = new DateTime(int.Parse(arrKeySearch[2]), int.Parse(arrKeySearch[3]), 30);
                }
                if (arrKeySearch[3] == "2")
                {
                    date_end = new DateTime(int.Parse(arrKeySearch[2]), int.Parse(arrKeySearch[3]), 28);
                }
            }
            if (arrKeySearch.Count() == 6)
            {
                date_start = new DateTime(int.Parse(arrKeySearch[0]), int.Parse(arrKeySearch[1]), int.Parse(arrKeySearch[2]));
                date_end = new DateTime(int.Parse(arrKeySearch[3]), int.Parse(arrKeySearch[4]), int.Parse(arrKeySearch[5]));
            }

            HoaDonBUS hd_BUS = new HoaDonBUS();
            List<shop_hoadon> hd_list = hd_BUS.TimKiemHoaDonTheoThoiGian(date_start, date_end);

            int totalrow = hd_list.Count();
            String strContext = '"' + "default" + '"';
            String strTotalrow = '"' + totalrow.ToString() + '"';
            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            Response.Write("<h4><a href='#' onclick='ajax_manage_bill(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ");return false;'>" + "[Quay lại]</a> ></h4>");
            Response.Write("<br/>");

            if (hd_list.Count() == 0)
            {
                Response.Write("<h4>Không có dữ liệu hóa đơn nào thích hợp từ \"" +
                    String.Format("{0:dd/MM/yyyy}", date_start) + "\" đến \"" +
                    String.Format("{0:dd/MM/yyyy}", date_end) + 
                    "\"</h4>");
            }
            else
            {
                String page = "";
                if (Request.QueryString["page"] == null)
                {
                    return;
                }
                else
                {
                    page = Request.QueryString["page"];
                    if (page.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        page.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        page = page.Substring(1, page.Length - 2);
                    }
                }

                String strPage = '"' + page + '"';
                int iStart = iLimit * (int.Parse(page) - 1);
                int iEnd = iLimit * int.Parse(page);
                if (iEnd > totalrow)
                {
                    iEnd = totalrow;
                }

                Response.Write("<div id='content_management'>");
                Response.Write("<h4 id='management_title'>Kết quả tìm kiếm hóa đơn từ \"" +
                    String.Format("{0:dd/MM/yyyy}", date_start) + "\" đến \"" +
                    String.Format("{0:dd/MM/yyyy}", date_end) +                     
                    "\"</h4>");
                Response.Write("<br/>");
                Response.Write("<div id='management_list'>");

                Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
                Response.Write("<tbody>");
                Response.Write("<tr class='management_table_header' style='text-align: center;'>");
                Response.Write("<td width='30%'>Khách hàng</td>");
                Response.Write("<td width='20%'>Ngày mua</td>");
                Response.Write("<td width='20%'>Tổng tiền</td>");
                Response.Write("<td width='15%'></td>");
                Response.Write("<td width='15%'></td>");
                Response.Write("</tr>");

                int j = 1;
                //String strSearch = '"' + "true" + '"';

                UserBUS user_BUS = new UserBUS();
                aspnet_User user = new aspnet_User();

                for (int i = iStart; i < iEnd; i++)
                {
                    String strID = '"' + hd_list[i].MaHoaDon.ToString() + '"';

                    if (j == 1)
                    {
                        Response.Write("<tr class='management_celllight1'>");
                        j = 0;
                    }
                    else
                    {
                        Response.Write("<tr class='management_celllight0'>");
                        j = 1;
                    }
                    if (hd_list[i].UserId.ToString() != "" && hd_list[i].UserId.ToString() != null)
                    {
                        String strTmp = hd_list[i].UserId.ToString();
                        Guid guID = new Guid(strTmp);
                        user = user_BUS.LayUserTheoId(guID);
                        Response.Write("<td align='left' style='padding: 5px;'>" + user.UserName + "</td>");
                    }
                    else
                    {
                        Response.Write("<td></td>");
                    }
                    Response.Write("<td align='center' style='padding: 5px;'>" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", hd_list[i].NgayLap) + "</td>");
                    Response.Write("<td align='left' style='padding: 5px;'>" + hd_list[i].ThanhTien + "</td>");
                    Response.Write("<td align='center' style='padding: 5px;'>" +
                        "<div class='art-button-wrapper'>" +
                        "<span class='l'> </span>" +
                        "<span class='r'> </span>" +
                        "<a  class='art-button' href='#' onclick='ajax_view_detail_bill(" + strID + ");return false;'><span>Chi tiết</span></a>"
                        + "</div>" + "</td>");
                    if (hd_list[i].TinhTrang == false)
                    {
                        Response.Write("<td align='center' style='padding: 5px;'>" +
                            "<div class='art-button-wrapper'>" +
                            "<span class='l'> </span>" +
                            "<span class='r'> </span>" +
                            "<a  class='art-button' href='#' onclick='ajax_accept_bill(" + strID + "," + strTotalrow + "," + strLimit + ");return false;'><span>Duyệt</span></a>"
                            + "</div>" + "</td>");
                    }
                    else
                    {
                        Response.Write("<td></td>");
                    }
                    Response.Write("</tr>");
                }
                Response.Write("</tbody>");
                Response.Write("</table>");
                Response.Write("</div>"); /*end: div management_list */

                Response.Write("<div align='center'>");
                strContext = '"' + "previous" + '"';
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_bill(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + "," + strKeySearch + ");return false;'><span>Lùi</span></a>" +
                    "</div>");
                float fLimit = 10;
                double totalPage = Math.Ceiling(totalrow / fLimit);
                Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
                strContext = '"' + "next" + '"';
                Response.Write("<div class='art-button-wrapper'>" +
                    "<span class='l'> </span>" +
                    "<span class='r'> </span>" +
                    "<a  class='art-button' href='#' onclick='ajax_search_bill(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + "," + strKeySearch + ");return false;'><span>Tiếp</span></a>" +
                    "</div>");
                Response.Write("</div>"); /*end: div pageIndex */
                Response.Write("<div><select id=''>");
                strContext = '"' + "jump" + '"';
                for (int i = 1; i <= totalPage; i++)
                {
                    if (i == int.Parse(page))
                    {
                        Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                    }
                    else
                    {
                        strCount = '"' + i.ToString() + '"';
                        Response.Write("<option id='' value='" + i + "' onclick='ajax_search_bill(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + "," + strKeySearch + ")'>" + i + "</option>");
                    }
                }
                Response.Write("</select></div>");/*end: select */
                Response.Write("</div>"); /*end: div content_management */
            }
        }

        //*****************************************************************************************************
        // LAP DOANH THU
        // ****************************************************************************************************

        public void manage_income_default()
        {
            Response.Write("");
            Response.Write("<div id='choose_income_region' align='left'>"); /* begin: choose_income_region */

            Response.Write("<table border='0' width='300px'>"); /* start: table lua chon */
            Response.Write("<tbody>");
            Response.Write("<tr>"); /* begin: row lua chon */
            Response.Write("<td>");
            Response.Write("<label>Doanh thu </label>");
            Response.Write("<select id='choose_income' onclick='change_type_income(this.value)'>");
            Response.Write("<option value='choose_income_year'>Năm</option>");
            Response.Write("<option value='choose_income_quarter'>Quý</option>");
            Response.Write("<option value='choose_income_month'>Tháng</option>");
            Response.Write("</select>");
            Response.Write("</td>");
            Response.Write("<td align='right'>");
            Response.Write("<span id='span_income_quarter_or_month'>");
            Response.Write("</span>");
            Response.Write("năm <select id='value_income_year'>");
            int year_now = DateTime.Now.Year;
            for (int i = 1970; i <= year_now; i++)
            {
                if (i == year_now)
                {
                    Response.Write("<option selected value='" + i + "'>" + i + "</option>");
                }
                else
                {
                    Response.Write("<option value='" + i + "'>" + i + "</option>");
                }
            }
            Response.Write("</select>&nbsp;&nbsp;");
            Response.Write("</td>");
            Response.Write("</tr>"); /* end: row lua chon */
            Response.Write("<tr>"); /* begin: row nut lap bao cao */
            Response.Write("<td></td>");
            Response.Write("<td align='right'>");
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_income_show(\"default\",\"-1\",\"10\",\"-1\");return false;'><span>Lập</span></a>" +
                "</div>");
            Response.Write("</td>");
            Response.Write("</tr>"); /* end: row nut lap bao cao */
            Response.Write("<tr><td colspan='2' id='title_income'></td></tr>");
            Response.Write("</tbody>");
            Response.Write("</table>");/* end: table lua chon */

            Response.Write("</div>"); /* end: choose_income_region */
            Response.Write("<br/>");
            Response.Write("<br/>");

            Response.Write("<div id='show_income_region'>"); /* begin: show_income_region */
            Response.Write("</div>"); /* end: show_income_region */
        }

        public void manage_income_show()
        {
            String choose_income = "";
            if (Request.QueryString["choose_income"] == null)
            {
                return;
            }
            else
            {
                choose_income = Request.QueryString["choose_income"];
                if (choose_income.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                    choose_income.Substring(0, 1).ToString().CompareTo("\'") == 0)
                {
                    choose_income = choose_income.Substring(1, choose_income.Length - 2);
                }
            }

            String value_income_year = "";
            String value_income_quarter = "";
            String value_income_month = "";
            String page = "";

            DateTime date_start = new DateTime();
            DateTime date_end = new DateTime();
            String title_income = "";

            /* begin: xac dinh choose_income */
                if (Request.QueryString["value_income_year"] == null)
                {
                    return;
                }
                else
                {
                    value_income_year = Request.QueryString["value_income_year"];
                    if (value_income_year.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        value_income_year.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        value_income_year = value_income_year.Substring(1, value_income_year.Length - 2);
                    }
                }

                date_start = new DateTime(int.Parse(value_income_year), 1, 1);
                date_end = new DateTime(int.Parse(value_income_year), 12, 31);
                title_income = "THỐNG KÊ DOANH THU THEO NĂM " + value_income_year;

                if (Request.QueryString["page"] == null)
                {
                    return;
                }
                else
                {
                    page = Request.QueryString["page"];
                    if (page.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        page.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        page = page.Substring(1, page.Length - 2);
                    }
                }

            if (choose_income == "choose_income_quarter")
            {
                if (Request.QueryString["value_income_quarter"] == null)
                {
                    return;
                }
                else
                {
                    value_income_quarter = Request.QueryString["value_income_quarter"];
                    if (value_income_quarter.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        value_income_quarter.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        value_income_quarter = value_income_quarter.Substring(1, value_income_quarter.Length - 2);
                    }
                }

                /* begin: xac dinh quy */ 
                if (value_income_quarter == "1")
                {
                    date_start = new DateTime(int.Parse(value_income_year), 1, 1);
                    date_end = new DateTime(int.Parse(value_income_year), 3, 31);
                }
                if (value_income_quarter == "2")
                {
                    date_start = new DateTime(int.Parse(value_income_year), 4, 1);
                    date_end = new DateTime(int.Parse(value_income_year), 6, 30);

                }
                if (value_income_quarter == "3")
                {
                    date_start = new DateTime(int.Parse(value_income_year), 7, 1);
                    date_end = new DateTime(int.Parse(value_income_year), 9, 30);
                }
                if (value_income_quarter == "4")
                {
                    date_start = new DateTime(int.Parse(value_income_year), 10, 1);
                    date_end = new DateTime(int.Parse(value_income_year), 12, 31);
                }
                /* end: xac dinh quy */
                title_income = "THỐNG KÊ DOANH THU THEO QUÝ " + value_income_quarter + " NĂM " + value_income_year;
            }
            if (choose_income == "choose_income_month")
            {
                if (Request.QueryString["value_income_month"] == null)
                {
                    return;
                }
                else
                {
                    value_income_month = Request.QueryString["value_income_month"];
                    if (value_income_month.Substring(0, 1).ToString().CompareTo("\"") == 0 ||
                        value_income_month.Substring(0, 1).ToString().CompareTo("\'") == 0)
                    {
                        value_income_month = value_income_month.Substring(1, value_income_month.Length - 2);
                    }
                }

                date_start = new DateTime(int.Parse(value_income_year), int.Parse(value_income_month), 1);

                if ( value_income_month == "1" ||  value_income_month == "3" ||  value_income_month == "5" ||
                    value_income_month == "7" || value_income_month == "8" ||  value_income_month == "10" || 
                    value_income_month == "12")
                {
                    date_end = new DateTime(int.Parse(value_income_year), int.Parse(value_income_month), 31);
                }
                if ( value_income_month == "4" ||  value_income_month == "6" || value_income_month == "9" ||
                         value_income_month == "11")
                {
                    date_end = new DateTime(int.Parse(value_income_year), int.Parse(value_income_month), 30);
                }
                if ( value_income_month == "2")
                {
                    date_end = new DateTime(int.Parse(value_income_year), int.Parse(value_income_month), 28);
                }

                title_income = "THỐNG KÊ DOANH THU THEO THÁNG " + value_income_month + "/" + value_income_year;
            }
            /* end: xac dinh choose_income */

            HoaDonBUS hd_BUS = new HoaDonBUS();
            List<shop_hoadon> hd_list = hd_BUS.TimKiemHoaDonTheoThoiGian(date_start,date_end);

            int iLimit = 10;
            String strLimit = '"' + iLimit.ToString() + '"';
            int totalrow = hd_list.Count();
            String strTotalrow = '"' + totalrow.ToString() + '"';
            String strCount = '"' + "-1" + '"';
            String strContext = "";

            int iStart = (int.Parse(page) - 1) * iLimit;
            int iEnd = iLimit * int.Parse(page);
            float fLimit = 10;
            double totalPage = Math.Ceiling(totalrow / fLimit);
            if (iEnd > totalrow)
            {
                iEnd = totalrow;
            }

            String strTmp = "";

            Response.Write("<div id='content_management'>");
            /* begin: tieu de trang dau */
            if (page == "1")
            {
                Response.Write("<h2 style='text-align:center'>CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM</h2>");
                Response.Write("<h2 style='text-align:center'>Độc lập - Tự do - Hạnh phúc</h2>");
                strTmp = "ngày " + DateTime.Now.Day + ", tháng " + DateTime.Now.Month + ", năm " + DateTime.Now.Year;
                Response.Write("<h4 style='text-align:right'>"+strTmp+"</h4>");
                Response.Write("<h1 style='text-align:center'>"+title_income+"</h1>");
                Response.Write("<br/>");
                Response.Write("<br/>");
                Response.Write("<br/>");
                Response.Write("<br/>");
                Response.Write("<br/>");
                Response.Write("<br/>");
                Response.Write("<br/>");
                Response.Write("<br/>");
                Response.Write("<br/>");
            }
            /* end: tieu de trang dau */

            /* begin: chi tiet bao cao */
            Response.Write("<div id='management_list'>");

            Response.Write("<table class='management_table' width='550px' cellspacing='1' cellpadding='2' border='0' style='padding-top: 4px; margin-top: 4px;'>");
            Response.Write("<tbody>");
            Response.Write("<tr class='management_table_header' style='text-align: center;'>");
            Response.Write("<td width='10%'>STT</td>");
            Response.Write("<td width='40%'>Khách hàng</td>");
            Response.Write("<td width='30%'>Ngày lập</td>");
            Response.Write("<td width='20%'>Thành tiền</td>");
            Response.Write("</tr>");

            int j = 1;
            UserBUS user_BUS = new UserBUS();
            aspnet_User user = new aspnet_User();
            int stt = 0;

            for (int i = iStart; i < iEnd; i++)
            {
                if (j == 1)
                {
                    Response.Write("<tr class='management_celllight1'>");
                    j = 0;
                }
                else
                {
                    Response.Write("<tr class='management_celllight0'>");
                    j = 1;
                }

                stt = i + 1;
                Response.Write("<td align='center' style='padding: 5px;'>" + stt + "</td>");

                if (hd_list[i].UserId.ToString() != "" && hd_list[i].UserId.ToString() != null)
                {
                    String strID = hd_list[i].UserId.ToString();
                    Guid guID = new Guid(strID);
                    user = user_BUS.LayUserTheoId(guID);
                    Response.Write("<td align='left' style='padding: 5px;'>" + user.UserName + "</td>");
                }
                else
                {
                    Response.Write("<td></td>");
                }
                Response.Write("<td align='center' style='padding: 5px;'>" + String.Format("{0:dd/MM/yyyy HH:mm:ss}", hd_list[i].NgayLap) + "</td>");
                Response.Write("<td align='left' style='padding: 5px;'>" + hd_list[i].ThanhTien + " VND</td>");
                Response.Write("</tr>");
            }
            Response.Write("</tbody>");
            Response.Write("</table>");
            Response.Write("</div>"); /*end: div management_list */
            /* end: chi tiet bao cao */

            /* begin: tong ket trang cuoi */
            if (page == totalPage.ToString())
            {
                Response.Write("<br/>");
                Response.Write("<br/>");
                Response.Write("<br/>");
                decimal sum_money = 0;
                for (int i = 0; i < hd_list.Count(); i++)
                {
                    String tmp = hd_list[i].ThanhTien.ToString();
                    sum_money += decimal.Parse(tmp);
                }
                Response.Write("<h4 style='text-align:left'>Tổng tiền: " + sum_money + " VND</h4><br/><br/>");
                Response.Write("<div align='right'><table border=0 width=200px><tr><td align=center>");
                Response.Write("<b>Người lập biều</b><br/>");
                Response.Write("<i>(Ký và ghi rõ họ tên)</i>");
                Response.Write("</td></tr></table></div>");
            }
            /* end: tong ket trang cuoi */

            Response.Write("<div align='center'>");
            strContext = '"' + "previous" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_income_show(" + strContext + "," + strTotalrow + "," + strLimit + ",\"-1\"" + ");return false;'><span>Lùi</span></a>" +
                "</div>");
            Response.Write("<font id='pageIndex' size='6'>" + page + "/" + totalPage + "</font>");
            strContext = '"' + "next" + '"';
            Response.Write("<div class='art-button-wrapper'>" +
                "<span class='l'> </span>" +
                "<span class='r'> </span>" +
                "<a  class='art-button' href='#' onclick='ajax_manage_income_show(" + strContext + "," + strTotalrow + "," + strLimit + ",\"-1\"" + ");return false;'><span>Tiếp</span></a>" +
                "</div>");
            Response.Write("</div>"); /*end: div pageIndex */
            Response.Write("<div><select id=''>");
            strContext = '"' + "jump" + '"';
            for (int i = 1; i <= totalPage; i++)
            {
                if (i == int.Parse(page))
                {
                    Response.Write("<option id='' selected value='" + i + "'>" + i + "</option>");
                }
                else
                {
                    strCount = '"' + i.ToString() + '"';
                    Response.Write("<option id='' value='" + i + "' onclick='ajax_manage_income_show(" + strContext + "," + strTotalrow + "," + strLimit + "," + strCount + ")'>" + i + "</option>");
                }
            }
            Response.Write("</select></div>");/*end: select */
            Response.Write("</div>"); /*end: div content_management */
        }



    }
}
